Convert GUID string to octetBytes using PowerShell?

In conjunction with Andy Schneider's answer, you may find this function useful: function Convert-GuidToLdapSearchString( parameter(mandatory=$true, position=0)guid$Guid ) { ($Guid.ToByteArray() | foreach { '\' + $_. ToString('x2') }) -join '' } (I thought I had a more clever way to do this by adding a ScriptProperty to System. Guid, but I seem to have learned that you can't effectively add members to structs.) I'm not sure I understand what you are trying to accomplish based on your comment, but I think you may have just left out a $_.

Here is a somewhat contrived example that creates an object with a property that is a GUID, then uses select and Convert-GuidToLdapSearchString to convert the format. I hope it helps $o = New-Object PSObject -Property @{ GUID = $(Guid::NewGuid()) } $o $o | select @{ Name='SearchString'; Expression={ Convert-GuidToLdapSearchString $_. GUID } } This is not at all how I had imagined the function being used.

I expected you would use it to create an LDAP search clause such as: $searchString = Convert-GuidToLdapSearchString '{9e76c48b-e764-4f0c-8857-77659108a41e}' $searcher = adsisearcher"(msExchMailboxGuid=$searchString)" $searcher.FindAll().

In conjunction with Andy Schneider's answer, you may find this function useful: function Convert-GuidToLdapSearchString( parameter(mandatory=$true, position=0)guid$Guid ) { ($Guid.ToByteArray() | foreach { '\' + $_. ToString('x2') }) -join '' } (I thought I had a more clever way to do this by adding a ScriptProperty to System. Guid, but I seem to have learned that you can't effectively add members to structs.) I'm not sure I understand what you are trying to accomplish based on your comment, but I think you may have just left out a $_.

Here is a somewhat contrived example that creates an object with a property that is a GUID, then uses select and Convert-GuidToLdapSearchString to convert the format. I hope it helps. $o = New-Object PSObject -Property @{ GUID = $(Guid::NewGuid()) } $o $o | select @{ Name='SearchString'; Expression={ Convert-GuidToLdapSearchString $_.

GUID } } This is not at all how I had imagined the function being used. I expected you would use it to create an LDAP search clause such as: $searchString = Convert-GuidToLdapSearchString '{9e76c48b-e764-4f0c-8857-77659108a41e}' $searcher = adsisearcher"(msExchMailboxGuid=$searchString)" $searcher.FindAll().

That is extremely useful. I have managed to apply this to a single GUID, and it does indeed return it in the correct manner, in a very simple way. However, I am not sure how to incorporate this into my script.

I have declared the function at the top of the script, but when I call it with select-object @{Name="LDAP Guid";Expression={ConvertGuidToLdapSearchString(MailboxGUID)}} I don't get any output in the CSV file. I guess I am getting down to some basic PowerShell stuff here - any pointers? – dunxd Aug 26 at 9:53 I'd vote you up again if I could.

Thanks - this cracked it! You are right - this needs to go into a search clause so I can get the username associated with each mailbox. One step at a time... – dunxd Nov 4 at 15:48.

$guid = System. Guid"{21EC2020-3AEA-1069-A2DD-08002B30309D}" $guid.ToString() $guid.ToByteArray().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions