Author Posts

March 16, 2016 at 5:12 am

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

}
}

March 29, 2016 at 11:44 am

I may not be following. Is GrantSendOnBehalfTo an actual object, with properties? If it is, you could add a NoteProperty to it by using Add-Member, and populate that with whatever you want, and name it whatever you want.

$var | Add-Member -Member NoteProperty -Name Email -Value $email

Be careful using the word "array." PowerShell munges the difference, but there IS a difference between an array and a collection of objects.