Microsoft Azure – Resize Managed Disk via PowerShell
Pre-requisite: Azure
In this article, we will show you how to resize managed disks in Azure using a PowerShell script. Here we will be using the Azure Cloud Shell to update or resize the managed disk of an azure VM in simple easy steps. To perform this activity one should have Owner or Contributor or User Access Administrator access on the target Resource Group to perform this operation. Follow the below implementation steps to increase or decrease the size of the azure managed disk. Let’s get started.
Implementation Steps:
Step 1: Log in to the Azure portal.
Step 2: Open the Azure Cloud Shell and switch to PowerShell mode.
Step 3: Create a PowerShell using the touch command.
touch resizeDisk.ps1

Step 4: Open resizeDisk.ps1 to add the script.
code resizeDisk.ps1

copy and paste the below script into resizeDisk.ps1 file.
## Parameteres $ResourceGroupName = "" $VMName = "" $VM = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName $osDisk= Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $VM.StorageProfile.OsDisk.Name $osDisk.DiskSizeGB = "<Add New Size>" ## Deallocate the Azure VM Stop-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName ## Update Disk Size Update-AzDisk -ResourceGroupName $ResourceGroupName -Disk $osDisk -DiskName $osDisk.Name ## Start the Azure VM Start-AzVM -ResourceGroupName $ResourceGroupName -Name $vmName

Step 5:- Execute the file using the following run command.
./resizeDisk.ps1

Verify the Size of the Disk in Azure Portal by navigating to Azure VM Disk. That’s it you are done resizing the managed disk.
Please Login to comment...