0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Azure】App Serviceの.NETランタイム確認方法

Last updated at Posted at 2022-03-28

概要

AzureのApp Serviceにて、どの.NETランタイムバージョンが使用されているのかをコマンドで確認する方法

PowerShellスクリプトのパターン

以下のスクリプトを実行すると、JSONファイルで結果が作成される。
az loginしたローカルのPowerShellで実行してもいいし、CloudShellでPowerShellを選択して実行してもいい。

実行コマンド.txt
# Define a collection to hold the output
$runtimes = [System.Collections.Generic.List[object]]@()

# Get subscription id
Write-Progress "Fetching subscription id"
$sub = (az account show --query id -o tsv)

# Get all resource groups in the subscription
Write-Progress "Searching for resource groups"
$groups = (az group list --query "[].name" -o tsv)

# Set counter for group progress
$groupCounter = 1;

# Loop through each resource group to find all the web apps in it
foreach($group in $groups) {

    # Find web apps in the specified group
    Write-Progress "Searching for web apps in resource group $group" -PercentComplete (($groupCounter / $groups.Count) * 100)
    $apps =(az webapp list -g $group --query "[?kind=='app' || kind=='app,linux'].name" -o tsv)

    # Iterate the web apps
    foreach($app in $apps) {

        # Query the web app for versions
        Write-Progress "Querying web app $app"
        $appConfig = (az webapp show -n $app -g $group --query "{java:siteConfig.javaversion,netFramework:siteConfig.netFrameworkVersion,php:siteConfig.phpVersion,python:siteConfig.pythonVersion,linux:siteConfig.linuxFxVersion}") | ConvertFrom-Json

        # Define an output object
        $output = [PSCustomObject]@{
            group = $group
            name = $app
            host = $null
            runtime = $null
            version = $null
        }

        # Determine which type of app service it is and get the values accordingly
        if($appConfig.linux -eq "") {

            # Windows platform
            $output.host = "windows"

            # Query the app config to get the metadata for the current stack
            $uri = "https://management.azure.com/subscriptions/$sub/resourceGroups/$group/providers/Microsoft.Web/sites/$app/config/metadata/list?api-version=2020-10-01"
            $output.runtime = (az rest --method post --uri $uri --query "properties.CURRENT_STACK" -o tsv)

            # Determine the version of the relevant stack
            $output.version = switch($output.runtime) {
                "dotnet" {$appConfig.netFramework}
                "dotnetcore" {$null}
                "python" {$appConfig.python}
                "php" {$appConfig.php}
                "java" {$appConfig.java}
                default {$null}    
            }        

        } else {

            # Linux platform
            $output.host = "linux"

            # Split out the stack from the version
            $output.runtime = $appConfig.linux.split("|")[0]
            $output.version = $appConfig.linux.split("|")[1]

        }

        $runtimes.Add($output)
    }
実行結果サンプル.json
[
  {
    "group": "sample-group",
    "name": "sample-ruby-app",
    "host": "linux",
    "runtime": "RUBY",
    "version": "2.6"
  },
  {
    "group": "php-group",
    "name": "sample-php-app",
    "host": "windows",
    "runtime": "php",
    "version": "7.3"
  },
  {
    "group": "linux-apps",
    "name": "sample-node-app",
    "host": "linux",
    "runtime": "NODE",
    "version": "14-lts"
  },
  {
    "group": "linux-apps",
    "name": "sample-dotnetcore-app",
    "host": "linux",
    "runtime": "DOTNETCORE",
    "version": "3.1"
  }
]

Cloud Shell/Azure CLIのパターン

実行コマンドサンプル.txt
az webapp config show --resource-group <resource-group-name> --name <app-name> --query netFrameworkVersion

※リソースグループ・アプリの数だけ上記コマンドを実行する必要あり

実行結果サンプル.txt
{
  "Name": "linux-apps",
  "NetFrameworkVersion": "v4.0"
}

一括で流し込みたいなら、シェルスクリプトにして実行するなど

sample.sh
#!/bin/bash
az webapp config show --resource-group <resource-group-name> --name <app-name> --query netFrameworkVersion
az webapp config show --resource-group <resource-group-name> --name <app-name> --query netFrameworkVersion
az webapp config show --resource-group <resource-group-name> --name <app-name> --query netFrameworkVersion

実行コマンドサンプル.txt
sh sample.sh > sample_result.txt

参考

How to List App Services ( Webapp ) Runtimes?
現在の .NET Framework ランタイム バージョンを表示する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?