How to Resize Azure VM Disk using PowerShell?

Know how to check the Virtual machine Disk size and also how to resize managed Disk via PowerShell script in Azure.

PowerShell Script to Check VM Disk Size:

$ResourceGroupName = "_add_resource_group_name_"
$VMName = "_add_vm_name_"
$VM = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName
Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $VM.StorageProfile.OsDisk.Name | Select-Object Name,OsType,DiskSizeGB

PowerShell Script to Resize VM Managed Disks:

$ResourceGroupName = "_add_resource_group_name_"
$VMName = "_add_vm_name_"
 
## Store VM Details to $VM Variable
$VM = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName

## Deallocate the Azure VM
Stop-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName

## Update Disk Size
$osDisk= Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $VM.StorageProfile.OsDisk.Name
$osDisk.DiskSizeGB = "_add_new_size_"
Update-AzDisk -ResourceGroupName $ResourceGroupName -Disk $osDisk -DiskName $osDisk.Name

## Start the Azure VM
Start-AzVM -ResourceGroupName $ResourceGroupName -Name $vmName