# Automatic Windows VM Image update for Azure Local (HCI)

If you are using Azure Local (HCI), you might find the following PowerShell script [AzureLocalVMImageUpdater.ps](https://github.com/ztrhgf/azure_automation_runbooks/blob/main/AzureLocalVMImageUpdater.ps1)[1](https://github.com/ztrhgf/azure_automation_runbooks/blob/main/AzureLocalVMImageUpdater.ps1) useful.

[**What is it good for**](https://github.com/ztrhgf/azure_automation_runbooks/blob/main/AzureLocalVMImageUpdater.ps1)**?**

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 Images
        
    * `Reader` - 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 `$azureLocalClusterList` variable to match your environment in the [AzureLocalVMImageUpdater.ps](https://github.com/ztrhgf/azure_automation_runbooks/blob/main/AzureLocalVMImageUpdater.ps1)[1](https://github.com/ztrhgf/azure_automation_runbooks/blob/main/AzureLocalVMImageUpdater.ps1) script
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1761572302040/c7b5f839-34d6-4457-9d73-f1f5ca1f875d.png align="center")
    
* Use modified code in your Runbook
    
* Set the Runbook schedule and watch the magic :)
