I am running the following script but the -join "," for the owners is only returning the first result and not combining them with commas:
Connect-MgGraph -Scopes 'Application.Read.All'
$results = @()
#Get-AzureADApplication -All $true | %{
#Get-MgApplication | %{
Get-MgApplication -filter "AppID eq 'xyzxyzxyzxyz'" | % {
$app = $_
$owner = Get-MgApplicationOwner -ApplicationId $_.ID -Top 1
$app.PasswordCredentials |
%{
$results = [PSCustomObject] @{
DisplayName = $app.DisplayName;
AppID = $app.AppID;
CredentialType = "PasswordCredentials";
ExpiryDate = $_.EndDateTime;
#StartDate = $_.StartDate;
#KeyID = $_.KeyId;
Type = 'NA';
#Usage = 'NA';
THis Line Here --> Owners = $owner.AdditionalProperties.userPrincipalName -join ', ';
}
}
}
$results
Anyone have a quick fix to get the owners to process the join and list all owners with a comma? Owners = $owner.AdditionalProperties.userPrincipalName -join ', ';
CodePudding user response:
Here is you code $owner = Get-MgApplicationOwner -ApplicationId $_.ID -Top 1
A join is useless because you are limiting the amount of owner returned to 1 in all cases. Remove the -Top1
from your code and everything will work as expected.
$owner = Get-MgApplicationOwner -ApplicationId $_.ID
#...
$owner.AdditionalProperties.userPrincipalName -join ', '