Create Azure Service Health Alerts for All Resource Groups
Published Sep 19 2022 01:16 AM 6,828 Views
Microsoft

Introduction

I recently had a customer requirement for creating Azure Service Health Alerts. The way access was provided in Azure, meant that only specific users had access to their respective Resource Groups. We also did not want these users to receive alerts for all Resources in the Subscription [Default scope for Service Health Alerts].

 

Process Description:

This led to the creation of a PowerShell Script that will cycle through each Resource Group and create Service Health Alerts for all Contributors or Owners.

 

Script Explanation

*Please only run this script in PowerShell 7 and above as I am using the -Parallel switch

  1. Breaking the script into a few different sections, we will start by connecting to Azure and getting a list of all subscriptions

 

wernerrall_0-1661515761677.png

 

  1. Then we will kick off a few Parallel processes to speed things up. These jobs will change context for each subscription and then find all resource groups

 

wernerrall_1-1661515761682.png

 

  1. Now we will find all Contributors on the resource group. If there are none we will look for Owners. We are only looking for objects that have a SignInName as we will need that for our email address assignment.

 

wernerrall_2-1661515761694.png

 

  1. By using the ARM Template for Health Alerts we can create a deployment with some parameters which I am randomizing the numbers for.

 

wernerrall_3-1661515761704.png

 

  1. If we take a closer look at the ARM Template one of the original problems were that this could only be assigned to the subscription().id scope

 

wernerrall_4-1661515761705.png

 

 

But by added two new parameters and modifying the scope I could get it to apply on ResourceGroup Level

 

wernerrall_5-1661515761707.png

 

 

Running the Script

 

  1. Simply grab the PowerShell from my GitHub Repo and save it into a PS1 file.

 

wernerrall_6-1661515761711.png

 

 

  1. Launch a PowerShell 7 or newer session, change directory to your ps1 file and run.

 

wernerrall_7-1661515761714.png

 

 

  1. The PowerShell session will launch an Azure Window to Authenticate you

 

wernerrall_8-1661515761716.png

 

 

wernerrall_9-1661515761717.png

 

You might see some warnings as I am not hiding any errors.

 

wernerrall_10-1661515761749.png

 

On Success you should see the ARM Template deployed.

 

wernerrall_11-1661515761830.png

 

We can confirm the deployment ran by looking in the deployments section of the resource group

 

wernerrall_12-1661515761835.png

 

wernerrall_13-1661515761840.png

 

Also if we go into Service Heath and click on Health Alerts we will see all our newly created alerts.

 

wernerrall_14-1661515761844.png

 

Find a copy of my code https://github.com/WernerRall147/RallTheory/tree/main/CreateServiceHealthAlertsForMyResources

 

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts or Power BI Dashboards are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts or Power BI Dashboards be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

Co-Authors
Version history
Last update:
‎Aug 26 2022 05:32 AM
Updated by: