Use Az.Resources commands to pull App Registrations' Client Secret expiration status from Azure AD - Requires PowerShell 7+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Module Az.Resources | |
#requires -Version 7 | |
<# | |
.SYNOPSIS | |
Based on Get-AppRegistrationExpiration by Cj-Scott | |
https://github.com/Cj-Scott/Get-AppRegistrationExpiration | |
#> | |
$applications = Get-AzADApplication | Where-Object { $_.KeyCredentials.DisplayName -gt 0 } | |
$today = (Get-Date).ToUniversalTime() | |
$appWithCredentials = @() | |
$appWithCredentials += $applications | Sort-Object -Property DisplayName | ForEach-Object -ThrottleLimit 12 -Parallel { | |
$application = $_ | |
Write-Host ('Fetching: {0}' -f $application.DisplayName) | |
$cred = $application | Get-AzADAppCredential -ErrorAction SilentlyContinue | |
foreach ($c in $cred) { | |
$daysToExpire = (New-TimeSpan -Start $using:today -End $c.EndDateTime).Days | |
if ($daysToExpire -le 0) { | |
$status = 'Expired' | |
} else { | |
$status = 'Valid' | |
} | |
[pscustomobject]@{ | |
ObjectId = $application.Id | |
ApplicationId = $application.AppId | |
AppRegistrationName = $application.DisplayName | |
KeyId = $c.KeyId | |
Type = $c.Type | |
StartDate = $c.StartDateTime -as [datetime] | |
EndDate = $c.EndDateTime -as [datetime] | |
Status = $status | |
DaysToExpire = $daysToExpire | |
Today = $using:today | |
} | |
} | |
} | |
$appWithCredentials | |
Write-Host 'Done.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment