Welcome to the Microsoft Q&A community.
To automate the execution of your PowerShell runbook as a pre-maintenance event before patching, and to run it on the created Hybrid Worker Group, follow these steps:
Step 1: Create and Publish the Runbook
- Create the Runbook: Ensure your PowerShell runbook is created and published in your Azure Automation account.
Assign Permissions: Assign the necessary permissions to the managed identity used by the runbook.
Step 2: Create a Webhook for the Runbook
Navigate to the Runbook: Go to your Azure Automation account and select the runbook you want to automate.
Create Webhook: Under the "Runbook" page, select "Webhooks" and then "Add Webhook".
Configure Webhook: Provide a name for the webhook, set the expiration date, and copy the URL provided. This URL will be used to trigger the runbook.
Step 3: Configure Pre-Maintenance Event
Navigate to Maintenance Configuration: Go to Azure Update Manager and select the maintenance configuration where your Arc-enabled machine is added.
Add Pre-Maintenance Event: Under the "Events" tab, select "+Event Subscription" to create a pre-maintenance event.
Configure Event Subscription:
Event Type: Select "Pre Maintenance Event".
**Endpoint Type**: Choose "Webhook".
**Webhook URL**: Paste the webhook URL you copied earlier.
**Event Schema**: Keep it as "Event Grid Schema".
Step 4: Configure Post-Maintenance Event
Repeat Steps for Post-Maintenance: Follow the same steps to create another runbook for starting the service after patching.
Create Webhook for Post-Maintenance Runbook: Create a webhook for this runbook as well.
Add Post-Maintenance Event: Under the "Events" tab, select "+Event Subscription" to create a post-maintenance event.
Configure Event Subscription:
Event Type: Select "Post Maintenance Event".
**Endpoint Type**: Choose "Webhook".
**Webhook URL**: Paste the webhook URL for the post-maintenance runbook.
**Event Schema**: Keep it as "Event Grid Schema".
Step 5: Test the Configuration
- Test Pre-Maintenance Event: Trigger the pre-maintenance event manually to ensure the runbook stops the app service as expected.
- Test Post-Maintenance Event: Trigger the post-maintenance event manually to ensure the runbook starts the app service as expected.
By following these steps, you can automate the execution of your PowerShell runbooks as pre- and post-maintenance events on your Arc-enabled server using Azure Automation and Azure Update Manager.
See:
- https://learn.microsoft.com/en-us/azure/update-manager/tutorial-webhooks-using-runbooks
- https://learn.microsoft.com/en-us/azure/update-manager/pre-post-events-schedule-maintenance-configuration
- https://learn.microsoft.com/en-us/azure/update-manager/tutorial-using-functions
I hope these helps. Let me know if you have any further questions or need additional assistance.
Also if these answers your query, do click the "Upvote" and click "Accept the answer" of which might be beneficial to other community members reading this thread.