Expired or soon-expiring app credentials
Every app registration in Microsoft Entra can carry client secrets and certificates, and each one has an end date after which it stops being valid. A read-only Microsoft Graph PowerShell script can list every credential that has already expired or will expire within a window you choose.
Why it matters
An app registration holds its credentials in two collections: passwordCredentials (client secrets) and keyCredentials (certificates and keys).[1] A password credential has an endDateTime, the date and time at which the password expires.[2] After that moment the credential no longer works, so whatever relies on it, such as an integration or a scheduled job, can fail to sign in.
Microsoft also notes that a generated secret value is only returned once, when it is created, and cannot be retrieved later.[2] That makes the end date easy to forget: nobody can look the secret up again, so the expiry has to be tracked separately.
Find it yourself
This script is read-only. It signs in with the Application.Read.All scope and only reads app registrations; it does not add, rotate or remove any credential.[3] It never prints secret values, because Microsoft Graph does not return them after creation.[2]
# Read-only: Get-* cmdlets only, scope Application.Read.All
param([Parameter(Mandatory)][int]$WindowDays) # your own warning window, in days
Connect-MgGraph -Scopes "Application.Read.All" -NoWelcome
$now = (Get-Date).ToUniversalTime()
$limit = $now.AddDays($WindowDays)
$rows = foreach ($app in Get-MgApplication -All) {
foreach ($c in $app.PasswordCredentials) {
[pscustomobject]@{ App = $app.DisplayName; AppId = $app.AppId; Type = "Secret";
Name = $c.DisplayName; EndDateTime = $c.EndDateTime }
}
foreach ($c in $app.KeyCredentials) {
[pscustomobject]@{ App = $app.DisplayName; AppId = $app.AppId; Type = "Certificate/key";
Name = $c.DisplayName; EndDateTime = $c.EndDateTime }
}
}
$rows |
Where-Object { $_.EndDateTime -and $_.EndDateTime -le $limit } |
Select-Object *, @{n = "Status"; e = { if ($_.EndDateTime -lt $now) { "Expired" } else { "Expiring" } }} |
Sort-Object EndDateTime |
Format-Table -AutoSize
Disconnect-MgGraphRun it as ./Get-ExpiringCredentials.ps1 -WindowDays <your window>. Pick the window that matches how long your team needs to rotate a credential.
Read the result
- Status = Expired: the end date has passed. If the app is still in use, something is probably already failing; if it is not in use, the app registration may be a candidate for clean-up.
- Status = Expiring: the credential is still valid but ends inside your window. Sort order puts the soonest first.
- Type: Secret rows come from passwordCredentials, Certificate/key rows from keyCredentials.[1]
- Several rows for one app: an app can hold more than one credential at a time, so an overlap during rotation is normal. An app whose only credential is on the list needs attention first.
The script covers app registrations only. Service principals (enterprise apps) can also carry password credentials,[2] so check those separately if you use them.
What to do next
- For each expiring credential, find the app owner and confirm the app is still needed.
- If it is, create the replacement credential before the old one ends, update the system that uses it, and only then remove the old one. Adding and removing credentials are write actions, so do them through your normal change process, not from this script.[1]
- Remove expired credentials on apps that are still needed, so the list shows only real risks.
- For apps nobody claims, decide whether to retire the registration.
- Record the next end date and re-run the script on a regular schedule of your own.
See it continuously
A one-off script only shows today's state. ConfigCobra's Inventory for Microsoft 365 includes a built-in "Expired or soon-expiring app credentials" risk view across your app registrations and enterprise apps (service principals), a relation graph that shows how objects connect, findings linked to the inventory objects they concern, and a CSV export. ConfigCobra reads your tenant with read-only Microsoft Graph permissions.
Go further
- Inventory & InsightsEvery user, app, device and resource in one inventory, with built-in risk views
- Identity & Access GovernanceFind inactive users, guests, admins and risky apps
- Microsoft 365CIS v7.0.0 · 160 controls · read-only Microsoft Graph
- Users inactive 90 daysMicrosoft 365 insight
- Users who never signed inMicrosoft 365 insight
- Users with no MFA registeredMicrosoft 365 insight
- External mail forwardingMicrosoft 365 insight
See it for your whole tenant, continuously
Inventory & Insights lists these risks with built-in views and CSV export, read-only.