Create VM option is Grayed out - Azure Disk

Well this was fun , We could easily create VM from Portal if we have disk already & i have done it so many times until i encounter this scenario which made me go through PS code twice and fortunately i could figure out what the problem is & why "create VM" is grayed out.

here the picture for you all and you could relate now -



Once you look at the picture you could see Create VM is grayed out and if you look again you will find Operating System option is also blank that is the issue which is not allowing disk to create VM.

If i will be more accurate , Azure is treating this Disk as Data disk not OS Disk hence there is no Option or grayed out option for Create VM.

Resolution : It can easily be fixed if you add one more command in your PS Code .i.e  -OsType

below is the code to create disk from VHD and we have selected -OsType Windows that helped us to fix the problem.

$storageType = 'Premium_LRS'
$location = "Central Us"
$storageAccountId = 'youstoragaeaccountID'
$sourceVHDURI = "yourvhduri"
$resourceGroupName = 'RG'
$diskName = 'yourdiskname'

$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI -OsType Windows 

New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName


Second Resolution is creating VM with the help PS Code , only then you could utilize this disk & below is the code that would help you -

$resourceGroupName = " name of your resource group"
$diskName = " name of the Managed Disk "
$location = " location should be same as the Managed Disk location"
$virtualNetworkName  = " name of an existing virtual network where virtual machine will be created"
$virtualMachineName  = " name of the virtual machine"
$virtualMachineSize = '' Size available in region and required"


$disk =  Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName

$VirtualMachine = New-AzVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize

$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows


#Create a public IP for the VM  (optional)
$publicIp = New-AzPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $location -AllocationMethod Dynamic

$vnet = Get-AzVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName

$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $nic.Id

New-AzVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $location


Hope this post would save you some time and helped you fixing your issue. 

7 comments:

Azure DevOps

Azure DevOps is a suite of development tools provided by Microsoft, designed to support the entire development lifecycle of a software proje...