Forum Discussion
PoorMens_Bravo
Jul 25, 2024Brass Contributor
Get-azureADApplication using ObjectID
Hi All, I have exported a csv file by running Get-OrganizationAddIn cmdlet script , but with that file i am not able to find out the owners of these integradted apps. Now i am importing this CSV file into Get-AzureADApplication cmdlet but i am unable to list any results by using the filter for ServicePrincipalObjectID , I am thinking just because it is going through thousands of applications within the tenant, so any help would be really helpful. Below is the snippet:
$securityid = Import-Csv -Path C:\Temp\OrgAddins-25Jul2024-162827.csv | select -ExpandProperty ServicePrincipalObjectId foreach($id in $securityid) { Get-AzureADApplication -ObjectId $id -all $true}1 Reply
hope the following helps you
# Import the CSV file and get the ServicePrincipalObjectId $securityid = Import-Csv -Path C:\Temp\OrgAddins-25Jul2024-162827.csv | select -ExpandProperty ServicePrincipalObjectId # Loop through each ServicePrincipalObjectId foreach ($id in $securityid) { # Retrieve the service principal $servicePrincipal = Get-AzureADServicePrincipal -ObjectId $id if ($servicePrincipal) { # Get the owners of the service principal $owners = Get-AzureADServicePrincipalOwner -ObjectId $servicePrincipal.ObjectId foreach ($owner in $owners) { Write-Output "Service Principal: $($servicePrincipal.DisplayName), Owner: $($owner.UserPrincipalName)" } } else { Write-Output "Service Principal with ObjectId $id not found." } }