创建 Azure VM 时 PowerShell 脚本永远不会停止

创建 Azure VM 时 PowerShell 脚本永远不会停止

我使用以下 powershell 脚本创建 azure VM。VM 已创建,但脚本从未停止或自动终止。我必须手动停止它。为什么会发生这种情况?

     $osDiskName = 'testdisk'
$virtualNetworkName = 'rg-vnet'
$virtualMachineName = 'myvmtest'
$Location = 'West US 2'
$virtualMachineSize = 'Standard_B2S'
$resourceGroupName = 'rg'
$disk = Get-AzDisk -ResourceGroupName $destinationResourceGroup -DiskName $osdiskname
$VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize
$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows
$vnet = Get-AzVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName
$nic = New-AzNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName          
$resourceGroupName -Location $Location -SubnetId $vnet.Subnets[0].Id
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id
 New-AzVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $Location

相关内容