1

I using the below powershell script to create azure VM. The VM got created but the script never stops or terminate automatically. I have to stop it manually. Why is this happening?

     $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
2
  • By the looks of things this is a bug with the module - please see this on GitHub, what appears to be a work around is to use the parameter -asjob on the command New-AzVM.
    – CraftyB
    May 6, 2020 at 12:18
  • I can see there its an issue never resolved.
    – biswajeet
    May 7, 2020 at 5:15

0

You must log in to answer this question.

Browse other questions tagged .