Whenever an application is live it’s important to keep it up and running without downtime. But what if your application stops suddenly just because you forget to update the expired ClientSecrets? It is going to affect your customers and business and you will get lot of escalation emails. Being an application owner, you don't want your application to have Application Downtime.
To avoid all these let’s implement a PowerShell script with help of Azure Function to monitor the expiration of your Azure AD app client secrets and send an email to the respective users in advance before it expires.
I hope you are you are already aware of below technologies which is needed for this implementation, if not please have a look at each official documentation.
Create Azure Timer Trigger
- Login to Azure Portal
- Search for Azure Function App and create the resource with required details.
- Ensure to choose the Function runtime as PowerShell Core

- Once the resource got created, go to the Functions menu in the left pane and click “Create Trigger” then choose “Timer Trigger”

How to change the schedule in Timer Trigger
- Timer triggers are based on schedules, if you want to change the time when the trigger should happen.
- Click on your function name and in the upcoming screen go to “Code + Test” menu.
- Select function.json from the files dropdown and look for the “schedule” object in the json to change the schedule timing.
- Learn more about the which expressions to use for the timing, please have a look at NCRONTAB expressions

How to enable AZ PowerShell module in Azure Functions
Azure functions by default support AZ module to perform operations in Azure Resources. Below are the steps to enable it.
Have a look at Azure PowerShell module commands to learn more about it.
- Go to your Function App and in the left pane click App Files.
- Select “requirements.psd1” from the files dropdown and uncomment the Az module as the below screen shot. If you wanted specific Az module version also you can modify it.






Greg GrovesPosted Feb 1, 2023, 2:58 PM
What should be the value of LogicApp_API_Url? Im getting a URI error and I think its because this is empty. 2023-02-01T15:30:36Z [Error] ERROR: Invalid URI: The hostname could not be parsed. Exception : Type : System.UriFormatException TargetSite : Name : CreateThis DeclaringType : uri MemberType : Method Module : System.Private.Uri.dll Message : Invalid URI: The hostname could not be parsed. Source : System.Private.Uri HResult : -2146233033 StackTrace : at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions) at System.Uri..ctor(String uriString) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.CheckProtocol(Uri uri) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.PrepareUri(Uri uri) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetRequest(Uri uri) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() at System.Management.Automation.Cmdlet.DoProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], UriFormatException FullyQualifiedErrorId : System.UriFormatException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand InvocationInfo : MyCommand : Invoke-RestMethod ScriptLineNumber : 47 OffsetInLine : 5 HistoryId : 1 ScriptName : C:\home\site\wwwroot\TimerTriggerEveryOtherDay\run.ps1 Line : Invoke-RestMethod -Method 'Post' -Headers $headers -Uri $env:LogicApp_API_Url -Body ($SecretsToExpire | ConvertTo-Json) PositionMessage : At C:\home\site\wwwroot\TimerTriggerEveryOtherDay\run.ps1:47 char:5 + Invoke-RestMethod -Method 'Post' -Headers $headers -Uri $env:Logi … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PSScriptRoot : C:\home\site\wwwroot\TimerTriggerEveryOtherDay PSCommandPath : C:\home\site\wwwroot\TimerTriggerEveryOtherDay\run.ps1 InvocationName : Invoke-RestMethod CommandOrigin : Internal ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\TimerTriggerEveryOtherDay\run.ps1: line 47