Finding info on an array

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 2 years, 2 months ago.

  • Author
  • #36605

    Recco Bucceri

    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={$ -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 :\Normal Accounts
    Depth : 2
    DistinguishedName : CN=John\, SmithM,OU=Normal Accounts,,DC=Domain1,DC=contoso,DC=com
    IsRelativeDn : False
    DomainId :
    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 "" | Where-Object{$_.GrantSendOnBehalfTo.Count -ge 1}

    foreach($Email in $Grant2)

    $DN = $Email.GrantSendOnBehalfTo.DistinguishedName
    foreach($Address in $DN)
    $EmailAddy = Get-Mailbox -Identity $Address


  • #37061

    Don Jones

    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.

You must be logged in to reply to this topic.