update vm disks in azure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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