From c4abfd1f9bf83488fcf7739c46c323cae9217dad Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 5 Feb 2026 14:15:26 +1100 Subject: [PATCH] Bug fix for "Write-Warning" error when resource no longer exists in azure and script throws warning before deleting alert rule --- azuremonitoring.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azuremonitoring.ps1 b/azuremonitoring.ps1 index bb2e912..9b50c5b 100644 --- a/azuremonitoring.ps1 +++ b/azuremonitoring.ps1 @@ -87,7 +87,7 @@ foreach ($rule in $alertRules) { } catch { # If the resource does not exist, delete the alert rule - Write-Warning "Resource $resourceId does not exist. Deleting alert rule $($rule.Name)..." -ForegroundColor Red -BackgroundColor Black + Write-Warning "Resource $resourceId does not exist. Deleting alert rule $($rule.Name)..." Remove-AzMetricAlertRuleV2 -ResourceGroupName $rule.resourceGroup -Name $rule.Name Write-Output "Alert rule $($rule.Name) deleted successfully." -ForegroundColor Yellow -BackgroundColor Black }