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...
sdtslmn
Jul 25, 2024MCT
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."
}
}