Azure Logic app to automate powershell runbook as pre-maintenance event befor patching via maintenance configuration

Vijay Naveen 20 Reputation points
2025-03-06T19:52:16.02+00:00

Logic app to automate powershell runbook on azure as pre-maintenance event before patching. powershell runbook is ready and published, the arc enabled machine is added to maintenance configuration. also configured hybrid worker group with that machine. now how to link that runbook and automate to run on created hybrid worker group before patching.

Basically that runbook to stop a particual app service on the Arc enabled server before patching.

and there will be one more post-maintenance event to start the service after patching with another runbook.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,388 questions
0 comments No comments
{count} votes

Accepted answer
  1. Chiugo Okpala 950 Reputation points MVP
    2025-03-06T20:13:54.07+00:00

    @Anonymous

    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

    1. 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

    1. Test Pre-Maintenance Event: Trigger the pre-maintenance event manually to ensure the runbook stops the app service as expected.
    2. 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:

    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.

    User's image

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Vijay Naveen 20 Reputation points
    2025-03-12T12:59:19.2966667+00:00

    Scratch my previous comment, got it, I missed to configure the parameter inside Webhook to run on Hybrid worker group, fixed that.

    Thank you for the response.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.