Conversion of msExchMailboxGuid from QuestAD
-
11-12-2019 - |
Question
I am trying to convert one of my PS scripts to query AD with Quest AD instead of native tools to speed up processing.
During my testing, I have come to the conclusion that the msExchMailboxGuid property is returned in a format that I need to convert.
This is the command I am running for testing:
$LDAPQuery = "(&(HomeMDB=*)(objectClass=user))"
$OUPath = "OU=users,DC=domain,DC=com"
$SearchResults = Get-QadUser -LdapFilter $LDAPQuery -SearchRoot $OUPath -ShowProgress -SizeLimit 1 -IncludedProperties "msExchMailboxGuid"
The msExchMailboxGuid value is being returned as this:
[PS] C:\Users\sysadmin>$SearchResults | Select msExchMailboxGuid
msExchMailboxGuid
-----------------
35CAF894943052409B77F30A6F8D40B4
If I run this, it returns:
[PS] C:\Users\sysadmin>[guid]"35CAF894943052409B77F30A6F8D40B4"
Guid
----
35caf894-9430-5240-9b77-f30a6f8d40b4
But I know that the msExchMailboxGuid for this user is actually this:
94f8ca35-3094-4052-9b77-f30a6f8d40b4
According to Exchange PS. So it's close but not quite right.
I wrote a function that converts the value to the right one using substring procedures.
Is there a better/more efficient way of returning the right value?
Function Convert-msExchMailboxGuid
{
param
(
$RawGuid
)
$ConvertedGuid = $RawGuid.SubString(6,2) + $RawGuid.SubString(4,2) + $RawGuid.SubString(2,2) + $RawGuid.SubString(0,2) + $RawGuid.SubString(10,2) + $RawGuid.SubString(8,2) + $RawGuid.SubString(14,2) + $RawGuid.SubString(12,2) + $RawGuid.SubString(16)
return ([guid]$ConvertedGuid).ToString()
}
This works OK but I hope this can be achieved in an easier way:
[PS] C:\Users\sysadmin>Convert-msExchMailboxGuid -RawGuid "35CAF894943052409B77F30A6F8D40B4"
94f8ca35-3094-4052-9b77-f30a6f8d40b4
Solution
I tried a few steps beyond this, and even with certain parameters behind the Get-QADUser commands, the rest was notably slower than my existing script. So I will leave this here in case someone wants to use my function for converting the GUID, but i'm not interested in the answer anymore.