azure-docs-powershell-samples/maintenance-auto-scheduler
Prudence 99b49b5887
Added Guidelines for automating Maintenance Control (#279)
2020-07-20 11:53:08 -05:00
..
images Added Guidelines for automating Maintenance Control (#279) 2020-07-20 11:53:08 -05:00
function.json Added Guidelines for automating Maintenance Control (#279) 2020-07-20 11:53:08 -05:00
readme.md Added Guidelines for automating Maintenance Control (#279) 2020-07-20 11:53:08 -05:00
run.ps1 Added Guidelines for automating Maintenance Control (#279) 2020-07-20 11:53:08 -05:00

readme.md

Scheduling Maintenance Updates with Maintenance Control and Azure Functions

Automating Maintenance Control Events

Azure recently launched the Maintenance Control feature which allows customers to imperatively apply platform maintenance to Azure Dedicated Hosts and isolated VMs. You may require a way to automatically check for updates and apply them according to a defined schedule. You can do this serverlessly using Azure Functions and PowerShell.

Setting up The Function

We will be implementing this using a Timer Triggered Azure Function. Remember that the Maintenance Control feature is only available to Dedicated Hosts and Isolated VMs. This function is only executable after you have assigned a configuration to your resource. Follow these steps to create your automatic maintenance control Function:

  1. Create a new Functions App on the Azure portal. (Note: This example is uses a PowerShell core runtime stack and the Azure Shell only supports it on Windows. If you would like to run the function on a Linux Operating System pick a different runtime stack).

  2. Navigate to your new functions app and create a Timer Triggered function. Use the cron scheduler to pick a preferred time for your function to run. You can also update your schedule on the Azure Portal as required.

  3. After you have created your function, you will need a method to login your app and access other resources on the portal. The recommended method is to make your App a System Assigned Managed Identity and assigning it a role with appropriate permissions. To assign a role:

    • Click Azure Role Assignments within the System Assigned tab: Add Identity

    • Then Add Role Assignment.

    • Select Subscription as scope and set role to contributor: Assign Role

  4. Now navigate to the run.ps1 file. This is where your function will live. Use Get-AzMaintenanceUpdate check if your Isolated VM or Dedicated Host has any scheduled updates.

  5. If updates are available, apply them using New-AzApplyUpdate.

  6. Save and Run your function. It will now automatically apply available updates to your resource each time the timer is triggered. Run Function