-1

I need to create an alert for any resource creation & send it over mail to me. I need to do this using Power-Shell script.

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
shristi
  • 109
  • 1
  • 1
  • 6
  • 2
    Please tell us what have you tried so far and any issues that you're getting there. – Gaurav Mantri Dec 02 '19 at 06:51
  • Check this https://learn.microsoft.com/en-us/azure/azure-monitor/platform/alerts-activity-log#create-with-azure-portal and https://social.msdn.microsoft.com/Forums/en-US/d524c3a1-cb0d-42b4-8f11-bcd1f25708da/how-to-get-an-alert-whenever-any-resource-is-created-in-the-azure-subscription?forum=windowsazuremanagement – Mohit Verma Dec 02 '19 at 08:07

1 Answers1

0

Configure activity log alert https://learn.microsoft.com/en-us/azure/azure-monitor/platform/activity-log-alerts. Once the alert is configured it can be made to send email.

If you want these alerts to be configured from powershell use these commandlets. Refer https://learn.microsoft.com/en-us/azure/azure-monitor/platform/powershell-quickstart-samples

$condition1 = New-AzActivityLogAlertCondition -Field 'category' -Equal 'Administrative'
$condition2 = New-AzActivityLogAlertCondition -Field 'operationName' -Equal 'Microsoft.Compute/virtualMachines/write'
$additionalWebhookProperties = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
$additionalWebhookProperties.Add('customProperty', 'someValue')
$actionGrp1 = New-AzActionGroup -ActionGroupId '/subscriptions/<subid>/providers/Microsoft.Insights/actiongr1' -WebhookProperty $additionalWebhookProperties
Set-AzActivityLogAlert -Location 'Global' -Name 'alert on VM create' -ResourceGroupName 'myResourceGroup' -Scope '/subscriptions/<subid>' -Action $actionGrp1 -Condition $condition1, $condition2

Let me know if this helps.

Arun
  • 324
  • 1
  • 8