是否有设置动态 Windows 虚拟桌面主机池负载平衡方法的解决方案?

Is there has a solution to setting a dynamic Windows Virtual Desktop Host pool load-balancing methods?

我想在每天晚上 19​​ 点到上午 11 点将主机池负载平衡方法从广度优先更改为深度优先,以降低 VM 的成本。

例如: 主机池负载平衡方法:呼吸优先,11:00 AM ~ 17:00 PM 主机池负载均衡方法:深度优先,17:00 PM ~ 11:00 AM

有知道这方面的人吗? 参考:SET-Hostpool

您可以使用 azure 自动化 运行book 来执行此操作,请按照以下步骤操作。

1.Navigate 到蔚蓝门户,create an automation account, then create a powershell runbook

2.Navigate 到自动化账户 -> Modules -> Browse Gallery -> 搜索 powershell 模块 Microsoft.RDInfra.RDPowerShell 并导入它,导入后,它看起来像下面。

3.When 您使用设置 Create Azure Run As account 作为 Yes 创建自动化帐户,它将在您的 Azure AD 租户中创建一个 AD 应用程序和一个服务主体,其名称将就像 automationaccountname_fc2Wgay6EkHrpgrpMSbF1V8uc6LVDkz9tgb8T6YUhaQ=。在azure 运行book中,您无法使用交互式方式登录虚拟桌面,因此选择使用服务主体(运行作为帐户)登录。

登录前,您需要创建角色分配,以便服务主体可以登录到虚拟桌面,只需按照此 link

Add-RdsAccount -DeploymentUrl "https://rdbroker.wvd.microsoft.com"
Get-RdsTenant

$myTenantName = "<Windows Virtual Desktop Tenant Name>"
New-RdsRoleAssignment -RoleDefinitionName "RDS Owner" -ApplicationId <service-principal-appid> -TenantName $myTenantName

要在上面的脚本中找到 ApplicationId,请导航到门户中的 Azure Active Directory -> App registrations -> All applications -> 找到您的广告应用程序运行 作为帐户 -> 获取如下所示的 ApplicationId

4.Navigate 到步骤 1 中创建的 powershell 运行book,使用如下脚本,它将主机池设置为使用广度优先负载平衡。

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Windows Virtual Desktop..."
    Add-RdsAccount `
        -DeploymentUrl "https://rdbroker.wvd.microsoft.com" `
        -AadTenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

Set-RdsHostPool -TenantName "<contoso>" -Name "<contosoHostPool>" -BreadthFirstLoadBalancer

然后保存运行book1,并创建另一个运行book2,使用下面的脚本,它设置主机池使用深度优先负载平衡。

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Windows Virtual Desktop..."
    Add-RdsAccount `
        -DeploymentUrl "https://rdbroker.wvd.microsoft.com" `
        -AadTenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

Set-RdsHostPool -TenantName "<contoso>" -Name "<contosoHostPool>" -DepthFirstLoadBalancer -MaxSessionLimit 10

5.Navigate 到 运行book1 中的 Schedule,有关如何使用它的更多详细信息,请参阅此 doc。例如,在您的情况下,只需像下面这样设置即可。然后 运行book1 将 运行 每天 11:00 AM。在运行book2中也是一样的逻辑,那么运行book2每天都会运行在17:00 PM。配置时间表后,整理两本书 运行。