Reputation: 367
The following script runs okay, I can see it doing the designed task (deploying 500 virtual machines) but I get a warning from New-AzVM that tells me that it's using the most sane storage account that it can reach. I've been having a lot of problems with the virtual machines that it spins up, and they are spinning up very slowly (at a speed of about 10 per hour) and I was wondering if the problem might be that I'm unable to designate a storage account as part of the configuration.
I've done quite a few google searches, looking through the microsoft documentation on these scripts, and haven't found a way to specify the configuration I want.
The script I'm using is this:
$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
}
(details replaced with filler of course)
results like:
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.
This machine was created in about 2 minutes.
Some machines seem to take less than a minute to spin up, while others take upwards of 10.
It selects the proper storage account I want to use, at least.
Upvotes: 0
Views: 798
Reputation: 20067
When you create a VM if you enable diagnostics you have to specify a storage account. In this case if you doesn't specify a SA it will create a storage account for you or select any existing storage account.
You could use Set-AzureRmVMBootDiagnostics to modifies boot diagnostics properties of a virtual machine to specify the storage configuration.
Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "ResourceGroup11" -StorageAccountName "DiagnosticStorage"
Upvotes: 1