Monitor Your Expired Azure App Certificates
Author: Ofir Gavish
Inspired by: Eitan Talmi
Published on: October 17th 2024
This article will explain how to build an automation account to monitor your Azure App Certificates and secrets and to notify you before expiration.
Create the Automation Account
- Go to Azure Automation Accounts.
- Click on Create and create a new account.
- Go to your Automation Account
- Select Overview and then select Try Runtime environment experience.
- Click on Create a Runtime environment
- Enter a name, Choose Powershell in the Language, and 7.2 in the Runtime version, give it a Description if you'd like:

Add Modules to the Runtime Environment
Click on Next, and then Add from gallery

Search for "Microsoft.Graph" and add it:

Click on Add from gallery again, search for Exchange and add the module:

Repeat until you have the following modules added:

Then click Next, and Create.
Enable Managed Identity for the Automation Account and assign permissions
On the Automation Account page, Click on Account Settings on the side bar, then click on Identity
Enable the System Assigned Managed Identity - switch to On and copy the Object ID:

Go to Entra ID, click on Roles and administrators, Click on Application Administrator, Click on Add assignments -> click on selected members and paste the Object ID
Once done it should look like this:

Assign Permissions on Azure Email communication service:
- Under your Azure Communication service Click on Access Contol (IAM)
- Click on Add -> Add role assignment -> Click on the "Priviliged administrator roles" -> choose the Contributor role and click Next:
- Under "Assign access to" choose the "Managed Identity" radio button and click on Select members, choose your Automation runbook from the drop down list
- Click on Select, and then Review + assign to save the assignment

Deploy the Code
- Go to your Azure Automation Account
- Click on Process Automation,Click on Runbooks and then on Create a runbook.
- Type a name, select PowerShell as the runbook type, and select the runtime environment you created earlier.
- Click on Review + Create
- Click on Edit and paste the code from github here
- Make sure to follow the instuctions what to edit in the code
Saving the Runbook
- Click on Save.
- Click on Test pane, then on Start, and ensure your code runs without errors.
- Go back to your code and click on Publish.
Add a Schedule
- Click on Runbooks and then on the runbook you created.
- Click on Link to schedule.
- Click on Link a schedule to your runbook.
- Click on Add a schedule, fill up the details, and click on Create.
Limit the Application
- Create a Mail-Enabled security group.
- In this group, add the members which the app should send email to.
- From PowerShell, connect to Exchange Online.
- Run the following command:
New-ApplicationAccessPolicy -AppId <ClientID> -PolicyScopeGroupId <MailEnabledSecurityGroup> -AccessRight RestrictAccess -Description "Limit my app application emails sending"
Following these steps will help you effectively monitor your Azure App Certificates and receive notifications before they expire.