Skip to content

Instantly share code, notes, and snippets.

Created April 27, 2021 21:18
What would you like to do?
update vm disks in azure
#select sub
Select-AzSubscription -Subscription 95a20cd8-ca92-4b1e-9d7a-f9ca650b8811
# Name of the resource group that contains the VM
$rgName = 'AMS-prd'
# Choose between Standard_LRS, StandardSSD_LRS and Premium_LRS based on your scenario
$storageType = 'Premium_LRS'
#Get list of all VM's
$vmlist = Get-AzVM -ResourceGroupName $rgName
foreach ($v in $vmlist){
#stop VM
Stop-AzVM -ResourceGroupName $rgName -Name $ -Force
# Get all disks in the resource group of the VM
$vmDisks = Get-AzDisk -ResourceGroupName $rgName
# For disks that belong to the selected VM, convert to Premium storage
foreach ($disk in $vmDisks)
if ($disk.ManagedBy -eq $v.Id)
$disk.Sku = [Microsoft.Azure.Management.Compute.Models.DiskSku]::new($storageType)
$disk | Update-AzDisk
Start-AzVM -ResourceGroupName $rgName -Name $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment