Skip to content

Instantly share code, notes, and snippets.

@nshores
Created April 27, 2021 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/244e6f012de2acf6fcc5ef69ca4eccfe to your computer and use it in GitHub Desktop.
Save nshores/244e6f012de2acf6fcc5ef69ca4eccfe to your computer and use it in GitHub Desktop.
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 $v.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 $v.name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment