If you just blocked users from registering applications, or you are just analyzing your Enterprise applications, you may find that there is a lot of work ahead of you.
First, you may want to find if there are applications with no user assigned. Then you may wonder if there are applications without sign-ins in the last 30 days.
To ease your work, you may find it useful to query all applications for these fields and get the output in a CSV.
This script is freely based on Ravenswood PoC code, with the intent of helping out and refining it a bit.
First, head to Enterprise Applications | AAD and click “Download (Export)”, then download the CSV.

This is done via the portal and not via PowerShell for practicality, since at the moment, to get the same exact filters (e.g. “Microsoft Applications”, “Enterprise Applications”, etc.) that you get on the portal, you would have to query Graph.
Then save this script:
$AllApplications=Import-Csv .\EnterpriseAppsList.csv
$applications=$allapplications | where {$_.applicationtype -ne "Microsoft application"}
ForEach($Application in $Applications){
#Retrieve the objectid and signin logs, format the user assigned to the app
$app=Get-AzureADServicePrincipal -all $true | where {$_.objectid -eq $application.id}
$Log = Get-AzureADAuditSignInLogs -All $true -filter "appid eq '$($App.AppID)'"
$userassigned = Get-AzureADServiceAppRoleAssignment -ObjectId $App.ObjectId | Select ResourceDisplayName,PrincipalDisplayName
$format=$userassigned.gettype()
if($format.basetype.name -eq "Object"){
$userassigned=[string]$userassigned
}
#Create a custom object for output
[PSCustomObject]@{
ApplicationName = $App.DisplayName
ApplicationID = $App.AppID
SignIns = $Log.count
Users = $userassigned.count
}
Start-Sleep 5
}
And finally, launch it:
.\StaleApplicationAnalysis.ps1 | Export-csv StaleApplicationCleanup.csv
The output will be along these lines, with an additional column for the App ID:

If you happen to find any optimization, feel free to let me know, and I’ll update the post.
Great work, thanks very much!
LikeLiked by 1 person