Here is a sample PowerShell script to retrieve the list of Enterprise Applications that have had no sign-ins for the past 30/60 days. This sample PowerShell script uses the Azure AD PowerShell module:
# Connect to Azure AD
Connect-AzureAD
# Set the number of days to check for stale applications
$staleDays = 30
# Get the list of enterprise applications
$apps = Get-AzureADServicePrincipal -All $true
# Filter out the applications that have had a sign-in within the last $staleDays days
$staleApps = $apps | Where-Object {
(Get-AzureADAuditSignInLogs -ObjectId $_.ObjectId -All $true -Top 1).createdDateTime -lt (Get-Date).AddDays(-$staleDays)
}
# Display the list of stale applications
$staleApps | Select-Object DisplayName, AppId
You can adjust the $staleDays
variable to set the number of days that you want to check for stale applications. You can also modify the Select-Object
statement to display additional properties if needed.