Resize Azure Windows OS disk script

less than 1 minute read

What happens when you have a Windows VM in Azure and you need to resize the disk size? You can’t do this in the portal, you need to use Powershell.

The full script

Function Resize-VM-OS-Disk(
    Select-AzSubscription SubscriptionName $SubscriptionName

    $vm = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $vmName

    Stop-AzVM -ResourceGroupName $ResourceGroupName -Name $vmName

    $disk= Get-AzureRmDisk -ResourceGroupName $ResourceGroupName -DiskName $vm.StorageProfile.OsDisk.Name
    $disk.DiskSizeGB = $NewDiskSize
    Update-AzDisk -ResourceGroupName $ResourceGroupName -Disk $disk -DiskName $disk.Name

    Start-AzVM -ResourceGroupName $ResourceGroupName -Name $vmName

Example to call the above script:

Resize-VM-OS-Disk -VmName "VM_NAME" -SubscriptionName "SUBSCRIPTION_NAME" -ResourceGroupName "RESOURCE_GROUP_NAME" -NewDiskSize 64