Get App Registrations by User Principal Name
$AccessToken = ""
$UserPrincipalName = ""
$Header = @{
"Authorization" = "Bearer $($AccessToken)"
}
$Params = @{
"Method" = "Get"
"Uri" = "https://graph.microsoft.com/v1.0/applications"
"Headers" = $Header
"ContentType" = "application/json"
}
$Result = Invoke-RestMethod @Params
$AllApplications = $Result.value
while ($Result.'@odata.nextLink') {
$Result = Invoke-RestMethod -Uri $Result.'@odata.nextLink' -Headers $Header
$AllApplications += $Result.value
}
$UsersApplication = @()
Foreach($Application in $AllApplications){
$Params.Uri = "https://graph.microsoft.com/v1.0/applications/$($Application.id)/owners?`$select=id,userPrincipalName"
$ApplicationInfo = (Invoke-RestMethod @Params).value
if($ApplicationInfo.userPrincipalName -eq $UserPrincipalName){# -and $ApplicationInfo.userPrincipalName.count -eq 1){
$UsersApplication += $Application
}
}