次の方法で共有


Azure Automationと Azure Logic Apps for Azure Virtual Desktop を使用してスケーリング ツールを設定する

この記事では、Azure Automation Runbook と Azure Logic App を使用して、Azure Virtual Desktop 環境でセッション ホスト VM を自動的にスケーリングするスケーリング ツールについて説明します。 スケーリング ツールの詳細については、「Azure Automationと Azure Logic Apps を使用してセッション ホストをスケーリングする」を参照してください。

注:

  • Azure Virtual Desktop のネイティブ自動スケーリング ソリューションは、プールされたホスト プールと個人用ホスト プールで一般提供されており、スケーリング スケジュールに基づいてセッション ホスト VM を自動的にスケールインまたはスケールアウトします。 構成を容易にするために自動スケーリングを使用することをお勧めします。 詳細については、「 自動スケーリング プラン」を参照してください。

  • Azure Automationと Azure Logic Apps を使用して、同じホスト プール上の自動スケーリングと共にセッション ホストをスケーリングすることはできません。 どちらか一方を使用する必要があります。

前提条件

スケーリング ツールの設定を開始する前に、次の準備ができていることを確認してください。

  • Azure Virtual Desktop ホスト プール
  • Azure Virtual Desktop サービスに構成され、登録されているセッション ホスト プール VM。
  • リソースを作成するために Azure サブスクリプションに割り当てられた 共同作成者 ロールベースのアクセス制御 (RBAC) ロールを持つユーザー。 マネージド ID を作成するには、 アプリケーション管理者 または 所有者 RBAC ロールも必要です。
  • Log Analytics ワークスペース (省略可能)。

ツールのデプロイに使用するマシンには、次のものが必要です。

準備ができたら、始めましょう。

Azure Automation アカウントを作成または更新する

注:

以前のバージョンのスケーリング スクリプトを実行している Runbook を使用するAzure Automation アカウントが既にある場合は、次の手順に従って更新されていることを確認するだけです。

まず、PowerShell Runbook を実行するには、Azure Automation アカウントが必要です。 このセクションで説明するプロセスは、PowerShell Runbook のセットアップに使用する既存のAzure Automation アカウントがある場合でも有効です。 設定方法は次のとおりです。

  1. PowerShell を開きます。

  2. 次のコマンドレットを実行して、Azure アカウントにサインインします。

    Login-AzAccount
    

    注:

    アカウントには、スケーリング ツールをデプロイする Azure サブスクリプションに対する共同作成者権限が必要です。

  3. 次のコマンドレットを実行して、Azure Automation アカウントを作成するためのスクリプトをダウンロードします。

    New-Item -ItemType Directory -Path "C:\Temp" -Force
    Set-Location -Path "C:\Temp"
    $Uri = "https://raw.githubusercontent.com/Azure/RDS-Templates/master/wvd-templates/wvd-scaling-script/CreateOrUpdateAzAutoAccount.ps1"
    # Download the script
    Invoke-WebRequest -Uri $Uri -OutFile ".\CreateOrUpdateAzAutoAccount.ps1"
    
  4. 次のコマンドレットを実行してスクリプトを実行し、Azure Automation アカウントを作成します。 パラメーターの値を入力するか、既定値を使用するようにコメントすることができます。

    $Params = @{
         "AADTenantId"           = "<Azure_Active_Directory_tenant_ID>"   # Optional. If not specified, it will use the current Azure context
         "SubscriptionId"        = "<Azure_subscription_ID>"              # Optional. If not specified, it will use the current Azure context
         "UseARMAPI"             = $true
         "ResourceGroupName"     = "<Resource_group_name>"                # Optional. Default: "WVDAutoScaleResourceGroup"
         "AutomationAccountName" = "<Automation_account_name>"            # Optional. Default: "WVDAutoScaleAutomationAccount"
         "Location"              = "<Azure_region_for_deployment>"
         "WorkspaceName"         = "<Log_analytics_workspace_name>"       # Optional. If specified, Log Analytics will be used to configure the custom log table that the runbook PowerShell script can send logs to
    }
    
    .\CreateOrUpdateAzAutoAccount.ps1 @Params
    

    注:

    ポリシーで特定のリージョンにスケーリング スクリプト リソースを作成できない場合は、ポリシーの割り当てを更新し、許可されているリージョンの一覧に必要なリージョンを追加します。

  5. 以前にオートメーション アカウントを作成したことがない場合、コマンドレットの出力には、Automation アカウント変数に暗号化された Webhook URI が含まれます。 Azure Logic App の実行スケジュールを設定するときにパラメーターとして使用するため、URI のレコードを保持してください。 既存の Automation アカウントを更新する場合は、PowerShell を使用して Webhook URI を取得 して変数にアクセスできます。

  6. Log Analytics の WorkspaceName パラメーターを指定した場合、コマンドレットの出力には Log Analytics ワークスペース ID とその主キーも含まれます。 Azure Logic App の実行スケジュールを設定するときに、後でパラメーターで使用する必要があるため、ワークスペース ID と主キーを書き留めます。

  7. Azure Automation アカウントを設定したら、Azure サブスクリプションにサインインし、チェックして、次の図に示すように、Azure Automation アカウントと関連する Runbook が指定したリソース グループに表示されていることを確認します。

    新しく作成されたAzure Automationアカウントと Runbook を示す Azure の概要ページの画像。

    Webhook の場所をチェックするには、Runbook の名前を選択します。 次に、Runbook の [リソース] セクションに移動し、[ Webhook] を選択します。

マネージド ID を作成する

Azure Automation アカウントが作成できたので、まだマネージド ID を設定していない場合も設定する必要があります。 マネージド ID は、Runbook が他のMicrosoft Entra関連リソースにアクセスし、重要な自動化プロセスを認証するのに役立ちます。

マネージド ID を設定するには、「Azure Automation アカウントにシステム割り当てマネージド ID を使用する」の指示に従います。 マネージド ID を作成したら、ホスト プール、VM などの Azure Virtual Desktop リソースに適切な共同作成者アクセス許可を割り当てます。完了したら、この記事に戻り、 Azure Logic App と実行スケジュールを作成 して、初期セットアップ プロセスを完了します。

Azure Logic App と実行スケジュールを作成する

最後に、Azure Logic App を作成し、新しいスケーリング ツールの実行スケジュールを設定する必要があります。 まず、まだ PowerShell セッションで使用する デスクトップ仮想化 PowerShell モジュール をダウンロードしてインポートします。

  1. PowerShell を開きます。

  2. 次のコマンドレットを実行して、Azure アカウントにサインインします。

    Login-AzAccount
    
  3. 次のコマンドレットを実行して、Azure Logic App を作成するためのスクリプトをダウンロードします。

    New-Item -ItemType Directory -Path "C:\Temp" -Force
    Set-Location -Path "C:\Temp"
    $Uri = "https://raw.githubusercontent.com/Azure/RDS-Templates/master/wvd-templates/wvd-scaling-script/CreateOrUpdateAzLogicApp.ps1"
    # Download the script
    Invoke-WebRequest -Uri $Uri -OutFile ".\CreateOrUpdateAzLogicApp.ps1"
    
  4. 次の PowerShell スクリプトを実行して、ホスト プールの Azure Logic App と実行スケジュールを作成します

    注:

    自動スケーリングするホスト プールごとにこのスクリプトを実行する必要がありますが、必要なAzure Automationアカウントは 1 つだけです。

    $AADTenantId = (Get-AzContext).Tenant.Id
    
    $AzSubscription = Get-AzSubscription | Out-GridView -OutputMode:Single -Title "Select your Azure Subscription"
    Select-AzSubscription -Subscription $AzSubscription.Id
    
    $ResourceGroup = Get-AzResourceGroup | Out-GridView -OutputMode:Single -Title "Select the resource group for the new Azure Logic App"
    
    $WVDHostPool = Get-AzResource -ResourceType "Microsoft.DesktopVirtualization/hostpools" | Out-GridView -OutputMode:Single -Title "Select the host pool you'd like to scale"
    
    $LogAnalyticsWorkspaceId = Read-Host -Prompt "If you want to use Log Analytics, enter the Log Analytics Workspace ID returned by when you created the Azure Automation account, otherwise leave it blank"
    $LogAnalyticsPrimaryKey = Read-Host -Prompt "If you want to use Log Analytics, enter the Log Analytics Primary Key returned by when you created the Azure Automation account, otherwise leave it blank"
    $RecurrenceInterval = Read-Host -Prompt "Enter how often you'd like the job to run in minutes, e.g. '15'"
    $BeginPeakTime = Read-Host -Prompt "Enter the start time for peak hours in local time, e.g. 9:00"
    $EndPeakTime = Read-Host -Prompt "Enter the end time for peak hours in local time, e.g. 18:00"
    $TimeDifference = Read-Host -Prompt "Enter the time difference between local time and UTC in hours, e.g. +5:30"
    $SessionThresholdPerCPU = Read-Host -Prompt "Enter the maximum number of sessions per CPU that will be used as a threshold to determine when new session host VMs need to be started during peak hours"
    $MinimumNumberOfRDSH = Read-Host -Prompt "Enter the minimum number of session host VMs to keep running during off-peak hours"
    $MaintenanceTagName = Read-Host -Prompt "Enter the name of the Tag associated with VMs you don't want to be managed by this scaling tool"
    $LimitSecondsToForceLogOffUser = Read-Host -Prompt "Enter the number of seconds to wait before automatically signing out users. If set to 0, any session host VM that has user sessions, will be left untouched"
    $LogOffMessageTitle = Read-Host -Prompt "Enter the title of the message sent to the user before they are forced to sign out"
    $LogOffMessageBody = Read-Host -Prompt "Enter the body of the message sent to the user before they are forced to sign out"
    
    $WebhookURI = Read-Host -Prompt "Enter the webhook URI that has already been generated for this Azure Automation account. The URI is stored as encrypted in the above Automation Account variable. To retrieve the value, see https://learn.microsoft.com/azure/automation/shared-resources/variables?tabs=azure-powershell#powershell-cmdlets-to-access-variables"
    
    $Params = @{
         "AADTenantId"                   = $AADTenantId                             # Optional. If not specified, it will use the current Azure context
         "SubscriptionID"                = $AzSubscription.Id                       # Optional. If not specified, it will use the current Azure context
         "ResourceGroupName"             = $ResourceGroup.ResourceGroupName         # Optional. Default: "WVDAutoScaleResourceGroup"
         "Location"                      = $ResourceGroup.Location                  # Optional. Default: "West US2"
         "UseARMAPI"                     = $true
         "HostPoolName"                  = $WVDHostPool.Name
         "HostPoolResourceGroupName"     = $WVDHostPool.ResourceGroupName           # Optional. Default: same as ResourceGroupName param value
         "LogAnalyticsWorkspaceId"       = $LogAnalyticsWorkspaceId                 # Optional. If not specified, script will not log to the Log Analytics
         "LogAnalyticsPrimaryKey"        = $LogAnalyticsPrimaryKey                  # Optional. If not specified, script will not log to the Log Analytics
         "RecurrenceInterval"            = $RecurrenceInterval                      # Optional. Default: 15
         "BeginPeakTime"                 = $BeginPeakTime                           # Optional. Default: "09:00"
         "EndPeakTime"                   = $EndPeakTime                             # Optional. Default: "17:00"
         "TimeDifference"                = $TimeDifference                          # Optional. Default: "-7:00"
         "SessionThresholdPerCPU"        = $SessionThresholdPerCPU                  # Optional. Default: 1
         "MinimumNumberOfRDSH"           = $MinimumNumberOfRDSH                     # Optional. Default: 1
         "MaintenanceTagName"            = $MaintenanceTagName                      # Optional.
         "LimitSecondsToForceLogOffUser" = $LimitSecondsToForceLogOffUser           # Optional. Default: 1
         "LogOffMessageTitle"            = $LogOffMessageTitle                      # Optional. Default: "Machine is about to shutdown."
         "LogOffMessageBody"             = $LogOffMessageBody                       # Optional. Default: "Your session will be logged off. Please save and close everything."
         "WebhookURI"                    = $WebhookURI
    }
    
    .\CreateOrUpdateAzLogicApp.ps1 @Params
    

    スクリプトを実行すると、次の図に示すように、Azure Logic App がリソース グループに表示されます。

    Azure Logic App の例の概要ページの画像。

    繰り返し間隔やタイム ゾーンの変更など、実行スケジュールを変更するには、Azure Logic App 自動スケーリング スケジューラに移動し、[編集] を選択して Azure Logic App Designerに移動します。

    Azure Logic App Designerの画像。ユーザーが繰り返し時刻と Webhook ファイルを編集できるようにする定期的なメニューと Webhook メニューが開きます。

スケーリング ツールを管理する

これでスケーリング ツールを作成したので、その出力にアクセスできます。 このセクションでは、役に立つ可能性のあるいくつかの機能について説明します。

ジョブの状態を表示する

すべての Runbook ジョブの概要された状態を表示したり、Azure portalで特定の Runbook ジョブの詳細な状態を表示したりできます。

選択したAzure Automation アカウントの右側にある [ジョブ統計] で、すべての Runbook ジョブの概要の一覧を表示できます。 ウィンドウの左側にある [ジョブ ] ページを開くと、現在のジョブの状態、開始時刻、完了時刻が表示されます。

ジョブの状態ページのスクリーンショット。

ログの表示とスケーリング ツールの出力

Runbook を開き、ジョブを選択することで、スケールアウト操作とスケールイン操作のログを表示できます。

Azure Automation アカウントをホストしているリソース グループ内の Runbook に移動し、[概要] を選択します。 次の図に示すように、概要ページの [ 最近使用したジョブ ] でジョブを選択し、スケーリング ツールの出力を表示します。

スケーリング ツールの出力ウィンドウの画像。

Runbook スクリプトのバージョン番号を確認する

使用している Runbook スクリプトのバージョンをチェックするには、Azure Automation アカウントで Runbook ファイルを開き、[表示] を選択します。 画面の右側に Runbook のスクリプトが表示されます。 スクリプトの [SYNOPSIS] セクションに、v#.#.#形式のバージョン番号が表示されます。 最新バージョン番号については、 こちらを参照してください。 Runbook スクリプトにバージョン番号が表示されない場合は、以前のバージョンのスクリプトを実行していることを意味し、すぐに更新する必要があります。 Runbook スクリプトを更新する必要がある場合は、「Azure Automation アカウントを作成または更新する」の手順に従います。

問題の報告

問題を報告するときは、トラブルシューティングに役立つ次の情報を提供する必要があります。

  • 問題の原因となったジョブの [ すべてのログ ] タブからの完全なログ。 ログを取得する方法については、「ログの 表示とスケーリング ツールの出力」の手順に従います。 ログに機密情報または個人情報がある場合は、問題を送信する前に削除できます。

  • 使用している Runbook スクリプトのバージョン。 バージョン番号を取得する方法については、「Runbook スクリプトのバージョン番号を確認する」を参照してください。

  • Azure Automation アカウントにインストールされている次の各 PowerShell モジュールのバージョン番号。 これらのモジュールを見つけるには、Azure Automation アカウントを開き、ウィンドウの左側にあるウィンドウの [共有リソース] セクションで [モジュール] を選択し、モジュールの名前を検索します。

    • Az.Accounts
    • Az.Compute
    • Az.Resources
    • Az.Automation
    • OMSIngestionAPI
    • Az.DesktopVirtualization

Log Analytics

Log Analytics を使用することにした場合は、Log Analytics ワークスペースの [ログ] ビューの [カスタム ログ] で、WVDTenantScale_CLという名前のカスタム ログにすべてのログ データを表示できます。 役に立つ可能性のあるサンプル クエリをいくつか一覧表示しました。

  • ホスト プールのすべてのログを表示するには、次のクエリを入力します。

    WVDTenantScale_CL
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • 現在実行中のセッション ホスト VM とホスト プール内のアクティブなユーザー セッションの合計数を表示するには、次のクエリを入力します。

    WVDTenantScale_CL
    | where logmessage_s contains "Number of running session hosts:"
         or logmessage_s contains "Number of user sessions:"
         or logmessage_s contains "Number of user sessions per Core:"
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • ホスト プール内のすべてのセッション ホスト VM の状態を表示するには、次のクエリを入力します。

    WVDTenantScale_CL
    | where logmessage_s contains "Session host:"
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • エラーと警告を表示するには、次のクエリを入力します。

    WVDTenantScale_CL
    | where logmessage_s contains "ERROR:" or logmessage_s contains "WARN:"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    

制限事項

このスケーリング スクリプトを使用してセッション ホスト VM をスケーリングする場合の制限事項を次に示します。

  • スケーリング スクリプトでは、標準と夏時間の間の時間の変更は考慮されません。