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