From 267309e335bb0fd90b34e529e7e2794751b542ee Mon Sep 17 00:00:00 2001 From: Pekka Savolainen Date: Tue, 26 Mar 2024 12:59:43 +0200 Subject: [PATCH 1/2] Updated methods to work with new az module --- Pinja.Azure.Alerts/Set-AlertRules.ps1 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Pinja.Azure.Alerts/Set-AlertRules.ps1 b/Pinja.Azure.Alerts/Set-AlertRules.ps1 index 18fb75e..a3dc9eb 100644 --- a/Pinja.Azure.Alerts/Set-AlertRules.ps1 +++ b/Pinja.Azure.Alerts/Set-AlertRules.ps1 @@ -115,15 +115,24 @@ function Set-AlertRules { } - if($PSCmdlet.ShouldProcess($ResourceGroup, "Set-AzActionGroup - azure-alerts")) - { - $alertRef = Set-AzActionGroup ` - -Name "azure-alerts" ` - -ResourceGroup $ResourceGroup ` - -ShortName "azure-alerts" ` - -Receiver $ActionGroupReceiver ` - -DisableGroup:$DisableAlerts ` - -WarningAction SilentlyContinue + if ($PSCmdlet.ShouldProcess($ResourceGroup, "Update-AzActionGrou - azure-alerts")) { + if (Get-AzActionGroup -Name "azure-alerts" -ResourceGroup $ResourceGroup) { + $alertRef = Update-AzActionGroup ` + -Name "azure-alerts" ` + -ResourceGroup $ResourceGroup ` + -ShortName "azure-alerts" ` + -WebhookReceiver $ActionGroupReceiver ` + -Enabled:(!$DisableAlerts) + } + else { + $alertRef = New-AzActionGroup ` + -Name "azure-alerts" ` + -ResourceGroup $ResourceGroup ` + -ShortName "azure-alerts" ` + -WebhookReceiver $ActionGroupReceiver ` + -Enabled:(!$DisableAlerts) + } + } } From 6128a5aa1521a82408ed8b4bed8ca20fdb973d3c Mon Sep 17 00:00:00 2001 From: Pekka Savolainen Date: Thu, 28 Mar 2024 12:10:04 +0200 Subject: [PATCH 2/2] Typofix --- Pinja.Azure.Alerts/Set-AlertRules.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pinja.Azure.Alerts/Set-AlertRules.ps1 b/Pinja.Azure.Alerts/Set-AlertRules.ps1 index a3dc9eb..b630a73 100644 --- a/Pinja.Azure.Alerts/Set-AlertRules.ps1 +++ b/Pinja.Azure.Alerts/Set-AlertRules.ps1 @@ -115,7 +115,7 @@ function Set-AlertRules { } - if ($PSCmdlet.ShouldProcess($ResourceGroup, "Update-AzActionGrou - azure-alerts")) { + if ($PSCmdlet.ShouldProcess($ResourceGroup, "Update-AzActionGroug - azure-alerts")) { if (Get-AzActionGroup -Name "azure-alerts" -ResourceGroup $ResourceGroup) { $alertRef = Update-AzActionGroup ` -Name "azure-alerts" `