This script helps to expand an Azure VM OS disk size. We normally can do this from the Azure Portal after we shut down the VM. However, some of the VMs running custom VHD based out of Windows Server 2003, we are not able to find the option to specify os disk size even after the VM is in Stopped (deallocated) status in portal.
The below script will perform the following
- Stop the VM
- Set the new disk size
- Start the VM after the size is expanded.
Login-AzureRmAccount $rgName = "<RG Name>" $vmName = "<VM Name>" $vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName $vm.StorageProfile.OSDisk.DiskSizeGB = 127 #Change this to desired value Update-AzureRmVM -ResourceGroupName $rgName -VM $vm Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName