Open In App

Microsoft Azure – Resize Managed Disk via PowerShell

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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
powershell

 

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

code resizeDisk.ps1
Open resizeDisk.ps1 to add the script

 

copy and paste the below script into resizeDisk.ps1 file.

## Parameters
$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
adding script

 

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

./resizeDisk.ps1
Execute the file

 

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.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads