So i have hit another brick wall…
I created the following script to extract all users that have the GrantSendOnBehalfTo populated.
Get-Mailbox -ResultSize 500000 | Where-Object{$.GrantSendOnBehalfTo.Count -ge 1} | select SamAccountName, UserPrincipalName, PrimarySmtpAddress, @{ n=“GrantSendOnBehalfTo”; e={$.GrantSendOnBehalfTo.name -join “;”}}, DistinguishedName |
Export-Csv -NoTypeInformation -Delimiter “;” -Path ‘D:\GrantSendOnBehalfTo_Test.csv’
Now when it exports, in the GrantSendOnBehalfTo column is populated with DisplayNames, but now the client wants email addresses instead of DisplayName.
The GrantSendOnBehalfTo multivalue looks as follows:
IsDeleted : False
Rdn : CN=John, Smith
Parent : Domain1.contoso.com\Normal Accounts
Depth : 2
DistinguishedName : CN=John, SmithM,OU=Normal Accounts,DC=Domain1,DC=contoso,DC=com
IsRelativeDn : False
DomainId : Domain1.contoso.com
ObjectGuid : 1bd02a02-1159-2a03-91ac-567
Name : John, Smith
What i am currently trying to achieve, is to use the DistinguishedName to get the mailbox details (Get-mailbox) and then combine it back into the multi-value array for that user.
I am at this point, but i have had a brain freeze on how to add the email addresses back into 1 variable, that then is associated with the original object i was querying:
$Grant2 = Get-Mailbox -Identity “John.Smith@Contoso.com” | Where-Object{$_.GrantSendOnBehalfTo.Count -ge 1}
foreach($Email in $Grant2)
{
$DN = $Email.GrantSendOnBehalfTo.DistinguishedName
foreach($Address in $DN)
{
$EmailAddy = Get-Mailbox -Identity $Address
}
}