Generate long Azure application secrets using PowerShell
17/09/2023
Azure portal limits secrets to expire every 2 years. Using PowerShell you can bypass this limit and create secrets past 2 years limit
First install Azure AD PowerShell module if not already installed.
Install-Module AzureAD
After installation connect to Azure AD and run following commands to create new secret. In our example we create secret that is valid for 10 years. Adjust $endDate = $startDate.AddYears(10)
accordingly:
Connect-AzureAD
$startDate = Get-Date
$endDate = $startDate.AddYears(10)
$value = New-AzureADApplicationPasswordCredential -ObjectId "REPLACE_WITH_OBJECTID_OF_APP_REGISTRATION"-StartDate $startDate -EndDate $endDate
$value
Object ID can be found under app properties in Azure AD.