Azure PowerShell 部署脚本运行速度极慢且缺少配置选项

Azure PowerShell deployment script runs extremely slowly and lacks configuration options

以下脚本运行正常,我可以看到它正在执行设计的任务(部署 500 个虚拟机),但我收到来自 New-AzVM 的警告,告诉我它正在使用它可以达到的最合理的存储帐户。我在使用它启动的虚拟机时遇到了很多问题,而且它们的启动速度非常缓慢(每小时大约 10 次),我想知道问题是否出在我无法将存储帐户指定为配置的一部分。

我已经进行了相当多的 google 搜索,查看了有关这些脚本的 Microsoft 文档,但没有找到一种方法来指定我想要的配置。

我使用的脚本是这样的:

$rgn = "VolumetricTest"
$passwd = ConvertTo-SecureString "password" -AsPlainText -Force
$logincred = New-Object System.Management.Automation.PSCredential("xadminx",$passwd)
$vnet = Get-AzVirtualNetwork -Name volumetric-vnet -ResourceGroupName VolumetricTest 
$loc = "East US"
$nsg_rdp_in = New-AzNetworkSecurityRuleConfig -name "RDP_in" -Protocol Tcp -Direction Inbound -Priority 300 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow
$nsg_rdp_out = New-AzNetworkSecurityRuleConfig -name "RDP_out" -Protocol Tcp -Direction Outbound -Priority 301 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow

$suffixes = @()

1..500 | ForEach-Object { $nm = $_.ToString("000"); $suffixes += @("$nm") } 

Foreach ( $suffix in $suffixes) {
    Write-Host $suffix
    $vmname = "SCLD-VT-W$suffix"
    Write-Host $vmname
    $nsg = New-AzNetworkSecurityGroup -Name "nsgW$suffix" -ResourceGroupName VolumetricTest -Location 'East US' -SecurityRules $nsg_rdp_in 
    Write-Host $nsg.Id 
    $net = New-AzNetworkInterfaceIpConfig -name "WNetAddr$suffix" -Subnet $( Get-AzVirtualNetworkSubnetConfig -Name default -VirtualNetwork $vnet ) -Primary
    $nic = New-AzNetworkInterface -Name "WNetif$suffix" -ResourceGroupName VolumetricTest -Location 'East US' -IpConfiguration $net -NetworkSecurityGroupId $nsg.Id 
    Write-Host $nic.Id 
    $vmconfig = New-AzVMConfig -VMName $vmname -VMSize "Standard_B2s" | Set-AzVMOperatingSystem -Windows -ComputerName $vmname -Credential $logincred | Set-AzVMSourceImage -PublisherName "microsoftwindowsdesktop" -Offer "Windows-10" -skus 'rs1-enterprise' -Version latest | Add-AzVMNetworkInterface -Id $nic.Id
    New-AzVM -ResourceGroupName $rgn -Location "East US" -VM $vmconfig
}

(细节当然用填充物代替)

结果如下:

014
SCLD-VT-W014
/subscriptions/00000000-0000-0000-0000-00000000/resourceGroups/VolumetricTest/providers/Microsoft.Network/networkSecurityGroups/nsgW014
/subscriptions/00000000-0000-0000-0000-00000000/resourceGroups/VolumetricTest/providers/Microsoft.Network/networkInterfaces/WNetif014
WARNING: Since the VM is created using premium storage or managed disk, existing standard storage account, volumetrictestbootdiag, is used for boot diagnostics.

这台机器是在大约 2 分钟内创建的。

有些机器似乎需要不到 1 分钟的时间才能启动,而其他机器则需要 10 分钟以上。

它至少选择了我想使用的正确存储帐户。

创建 VM 时,如果启用诊断,则必须指定存储帐户。在这种情况下,如果您未指定 SA,它将为您或 select 任何现有存储帐户创建一个存储帐户。

您可以使用 Set-AzureRmVMBootDiagnostics 修改虚拟机的启动诊断属性以指定存储配置。

Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "ResourceGroup11" -StorageAccountName "DiagnosticStorage"