Share via


Cant return string for msExchMailboxGUID

Question

Monday, May 26, 2014 1:08 AM

Hi All,

I am trying to get users msExchMailboxGUID as a string using the function below, however the msExchMailboxGUID is being returned as System.Byte[]. Any idea how to get this to display as a string?

Function Get-ADProps {
               
                                $root = [ADSI]"LDAP://*******"
                                $people = Import-Csv .\users.csv
                                $searcher = new-object System.DirectoryServices.DirectorySearcher($root)      
                               
                $ADObjects = @()
                                ForEach($person in $people){
                               
                                                                $ADuser = $person.InternetAddress
                                                                $searcher.filter = "(&(objectClass=user)(mail=$ADUser))"
                                                                $users = $searcher.FindAll()
                                                               
                                Foreach($user in $users)
                                {
                                                                [Array]$propertiesList = $user.Properties.PropertyNames
                                                                $obj = New-Object PSObject
                                
                                               
                                                                Foreach($property in $propertiesList)
                                                                {
                                                                                $obj | add-member -membertype noteproperty -name $property -value ([string]$user.Properties.Item($property))
                                                                }

                                                                $ADObjects += $obj
                                                }
               
                }
                Return $ADObjects
}

Get-ADProps | Select msExchMailboxGUID, SAMaccountName

Regards,

Michael. 

All replies (7)

Monday, May 26, 2014 10:41 AM ✅Answered

Joe, point 1 is very straight forward approach.You can try something like this

$pro = Get-ADUser -Identity 'TestAD' -Properties *
$string = $pro.msExchMailboxGuid
$bytes = [System.Text.Encoding]::Unicode.GetBytes($string)
[System.Text.Encoding]::ASCII.GetString($bytes)

Regards Chen V [MCTS SharePoint 2010]


Monday, May 26, 2014 4:41 PM ✅Answered

Joe, point 1 is very straight forward approach.You can try something like this

$pro = Get-ADUser -Identity 'TestAD' -Properties *
$string = $pro.msExchMailboxGuid
$bytes = [System.Text.Encoding]::Unicode.GetBytes($string)
[System.Text.Encoding]::ASCII.GetString($bytes)

Regards Chen V [MCTS SharePoint 2010]

Chen,  you method works too.  However I always hold the opinion that one should always use Exchange to do anything related to Exchange:

Import-Csv .\users.csv | select -ExpandProperty 'InternetAddress' | Get-Mailbox | select 'ExchangeGuid', 'SamAccountName'

The above one liner does the same job as the code in the OP, in readable format.


Monday, May 26, 2014 5:01 AM

Mike,

Two things you should consider:

  1. Use Exchange Management Shell, which will give you the mailbox GUID in a more printable format.
  2. Use System.Guid, which is very straight forward.

Cheers.


Monday, May 26, 2014 4:56 PM

I agree with you Joe,  Indeed one liner of yours does the same. I also want OP to use exchange method of doing. But, I thought of sharing Windows PowerShell quick way of doing.

Cheers :)

Regards Chen V [MCTS SharePoint 2010]


Tuesday, June 3, 2014 9:04 AM

Hi Michael,

I‘m writing to check if the suggestions were helpful, if you have any questions, please feel free to let me know.

If you have any feedback on our support, please click here.

Best Regards,

Anna

TechNet Community Support


Monday, June 9, 2014 7:28 PM

Hi,

yes thanks, Chen's reply was correct. I was not able to use exchange cmdlets in this instance so AD was the only option for me. Thanks for the reply Chen.


Tuesday, June 10, 2014 7:51 AM

Glad it worked. Cheers !

Regards Chen V [MCTS SharePoint 2010]