Im trying to generate a report of mailbox permissions out of Exchange Online. Here is the code:
$SendAs = @()
$Mailboxes = Get-mailbox | where {$_.Identity -notlike "DiscoverySearchMailbox*"}
Foreach ($MB in $Mailboxes) {
$SendAsTemp = Get-RecipientPermission $MB.userprincipalname | select identity,Trustee,AccessRights | `
Where-Object {$_.Trustee -notlike "*\Self" -and $_.Trustee -notlike "S-1-5*"}
if ($SendAsTemp) {
$SendAs += New-Object psobject -Property @{
Identity=$SendAsTemp.identity
Mailbox=$MB.primarysmtpaddress
Trustee=$SendAsTemp.Trustee
AccessRights=$SendAsTemp.AccessRights
}
}
}
The problem is that the output ($SendAs) is this;
Mailbox Trustee AccessRights Identity
shared@domain.com {user1@domain.com, user2@domain.com} {SendAs, SendAs} {shared, shared}
Its adding the multiple trustee permissions of 'shared' to a single row. What I want is this;
Mailbox Trustee AccessRights Identity
shared@domain.com user1@domain.com SendAs shared
shared@domain.com user2@domain.com SendAs shared
How do I achieve this?