Hi @Victor Day
You can create a scheduled Runbook in the Azure Automation Account and set the schedule to match the server's known reboot time. This way, the Runbook will trigger the script at the same time. If the VM state matches "deallocated", it will automatically update the SKU.
This approach helps avoid unnecessary reboots for VM SKU changes across all VMs.
$resourceGroup = "MyRG"
$targetSku = "E4ds_v5"
# Get all VMs in the resource group
$vms = Get-AzVM -ResourceGroupName $resourceGroup
foreach ($vm in $vms) {
$vmStatus = Get-AzVM -Name $vm.Name -ResourceGroupName $resourceGroup -Status
if ($vmStatus.PowerState -eq "VM deallocated") {
if ($vm.HardwareProfile.VmSize -ne $targetSku) {
Write-Output "Resizing VM '$($vm.Name)' to SKU '$targetSku'..."
$vm.HardwareProfile.VmSize = $targetSku
Update-AzVM -VM $vm -ResourceGroupName $resourceGroup
Write-Output "VM '$($vm.Name)' resized successfully."
} else {
Write-Output "VM '$($vm.Name)' already has the desired SKU '$targetSku'. Skipping."
}
} else {
Write-Output "VM '$($vm.Name)' is not deallocated. Skipping."
}
}
This way you avoid rebooting for VM SKU changes for all the VMs.
Reference: Create a standalone Azure Automation account
Change the size of a virtual machine
I hope this helps to resolve your query.
If the above is unclear and/or you are unsure about something, add a comment below.
Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members