Azure Automation: Increase Azure IaaS VM disks w/PowerShell


Several months ago I have written two functions Get-AzVmDisk and New-AzVmDisk that are intended to retrieve disk info and create new data disks for Azure VM(s).

Today to close the topic, we will talk about how to increase existing OS and Data disks. It will be Expand-AzVmDisk function.


  • The Expand-AzVmDisk function from my Azure Automation Az-Module can increase as well as OSDisk and DataDisk disk types.

  • The function has only two parameters -Disk and -SizeGB and both are mandatory.

  • For more convenience it supports pipeline input from the Get-AzVmDisk function to get disk object(s).

Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk | Expand-AzVmDisk -SizeGB 150
  • In all examples in this article I will use two auxiliary functions Select-AzResourceGroup and Select-AzObject, described in this article in the Helper functions paragraph.

Increase Data Disks

  • Let go straight to examples. Select a VM and check its current disk info and power state.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmPowerState
  • As we can see, this is powered on VM with OSDisk only. Let add to it a single 10GB Data disk and try to increase it to 20GB.
Select-AzResourceGroup | Select-AzObject VM | New-AzVmDisk OSDisk 10
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk DataDisk | Expand-AzVmDisk 20
  • Note that disk increase operation is irreversible (this mean you will not be able to decrease a disk anymore), therefore the function requires to confirm your intension. But if you’re sure what you’re doing, the -Confirm parameter is for you.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk DataDisk | Expand-AzVmDisk 25 -Confirm:$false


Increase OSDisk

  • The same way we can increase the OS disk too.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmDisk OSDisk | Expand-AzVmDisk 150


  • The only difference in the case of the OSDisk, if VM is powered on, the Expand-AzVmDisk will stop (deallocate) it first, then increase the disk and after that power VM on.
Select-AzResourceGroup | Select-AzObject VM | Get-AzVmPowerState



  • There are maximum disk size restrictions. Currently and this is recently changes, a OSDisk maximum size is 2TB or 2048GB and DataDisk is restricted to 4TB (4095GB).
  • Default OSDisk size would be 127GB, but a disk size is not exposed via Azure API and you will see it equal to 0 (zero) in the Get-AzVmDisk and Expand-AzVmDisk functions and blank in the Azure portal.

  • The real OS disk size can be seen in a VM guest OS only! Use the DISKPART.EXE utility or Disk Management applet for Windows guests and df for Linux to view it and … of course, extend your partition to utilize the just added disk space Emoj.

  • For more details about the function, please take a look at the content based help and examples.

Get-Command -Module Az-Module -Noun azvmdisk
Get-Help Expand-AzVmDisk -Full
Get-Help Expand-AzVmDisk -Examples
Get-Help Expand-AzVmDisk -Parameter Disk

You might also like

Expand-VMGuestPartition – Extend VM Guest Partition w/PowerCLi
How to find orphaned VHD files in the Azure
Azure Automation – How to stop/start Azure VM on schedule

3 thoughts on “Azure Automation: Increase Azure IaaS VM disks w/PowerShell

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s