How to identify Deallocated virtual machines in powershell and trigger automate using Logic app

Anonymous
2023-06-09T19:21:05.3266667+00:00

How to identify Deallocated virtual machines in PowerShell and trigger automate using Logic app

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
0 comments No comments
{count} vote

Answer accepted by question author
  1. MayankBargali-MSFT 70,981 Reputation points Moderator
    2023-06-12T06:35:40.15+00:00

    @Anonymous Thanks for reaching out.

    To identify deallocated virtual machines in PowerShell, you can use the Get-AzVM cmdlet and filter the results based on the PowerState property. Here's an example command that you can use:

    Get-AzVM | Where-Object {$_.PowerState -eq 'VM deallocated'}
    

    This command will return a list of all virtual machines that are deallocated.

    To trigger an automation using Azure Logic Apps when a virtual machine is deallocated, you can use the Azure Event Grid trigger in Logic Apps. Here are the steps to configure the trigger:

    For more details and steps, please refer to this document and you need to add the condition for deallocate event i.e. "Microsoft.Compute/virtualMachines/deallocate/action" so in Step 4 d. here please replace Microsoft.Compute/virtualMachines/write with Microsoft.Compute/virtualMachines/deallocate/action condition.

    When a virtual machine is deallocated, Azure Event Grid will send a notification to the Logic App, which will trigger the automation and you can further integrate your workflow.

    Hope the above helps. Feel free to get back to me if you need any assistance.

    Please "Accept Answer" if the answer is helpful so that it can help others in the community.


0 additional answers

Sort by: Most helpful

Your answer

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