Automatic Windows VM Image update for Azure Local (HCI)

If you are using Azure Local (HCI), you might find the following PowerShell script AzureLocalVMImageUpdater.ps1 useful.
The code replaces the Windows VM images in the specified Azure Local cluster(s) with the latest compatible version available in the Marketplace. So whenever you create a new VM, you will use the updated OS version.
Requirements
Image name
- Image must have a suffix
-<number>(i.e. Windows2025-01), so if the image gets replaced with the new one, the<number>can be increased to emphasize the change
Permissions
IAM (RBAC) assignments for the subscription where the HCI cluster is located
Azure Stack HCI Administrator- to be able to manage Azure Local VM ImagesReader- to be able to query cluster health, VM Images, and other required resources
PowerShell
- Core (to be able to use parallel processing)
PowerShell modules
Az (Az.Accounts, Az.ResourceGraph)
Azure Cli
AzureLocalStuff
How to use it?
Create Azure Automation Runbook
Add required PowerShell modules
Grant required IAM role assignments to the Automation Account Managed Identity
Customize the
$azureLocalClusterListvariable to match your environment in the AzureLocalVMImageUpdater.ps1 script
Use modified code in your Runbook
Set the Runbook schedule and watch the magic :)




