none
Cannot add the msExchArchiveGUID in Powershell RRS feed

  • Question

  • I cannot add the GUID value for msExchArchiveGUID in powershell. Error reports of "constraint violation" or "A value for the attribute was not in the acceptable range of values" depending on which powershell cmdlet is used. From what I can tell the value that needs to be input needs to be up to 16 characters. Anything more and it errors. For example, the GUID value I need to write is 5C669E441173CF4394995E43EC8ED9ED. When pasted using ADSIEdit the output looks like: 5C 66 9E 44 11 73 CF 43 94 99 5E 43 EC 8E D9 ED. If I add the same value using Powershell it errors. How can I write the value in Powershell to give the same result like adding using ADSIEdit? E.g Set-aduser -identity "someone" -add @{msExchArchiveGUID="A format the works! "}.

    //A

    Thursday, June 8, 2017 12:15 PM

Answers

  • Where are you getting this GUID from?  It is a bi nary GUID and can be converted in one step:

    [guid]$binaryguid

    Just cast the array to a GUID.

    You cannot correctly convert a hex string to a GUID in most cases. It will not be the correct value.

    The output in AdsiEdit is just a string representation of a byte array.  You can get the GUID from any object as a GUID by just asking for it.

    PS C:\scripts> Get-AdComputer ws701 | select objectGUID
    
    objectGUID
    ----------
    8e4ddb8a-4d80-4f4c-8704-a18597e8b013

    Every object in AD has a GUID.  Some objects reference GUIDs as byte arrays which will be displayed in ADSIEdit as hex pairs one per byte.

    PS C:\scripts> $guid = Get-AdComputer ws701 | select -expand objectGUID
    PS C:\scripts> $bytearray = $guid.ToByteArray()
    PS C:\scripts> [guid]$bytearray
    
    Guid
    ----
    8e4ddb8a-4d80-4f4c-8704-a18597e8b013

    What object property are you trying to convert?

    For Exchange objects get the object and reference its "objectGuid" property.

    If ExchOnline then see this article: https://blogs.msdn.microsoft.com/harishck/2017/02/26/update-msexcharchiveguid-in-bulk-from-exchange-online-to-on-premise-ad/

    With objects there is almost never any need to play with strings.


    \_(ツ)_/



    • Edited by jrv Sunday, June 11, 2017 8:08 PM
    • Marked as answer by Andrew_Stevens Sunday, June 11, 2017 8:29 PM
    Sunday, June 11, 2017 8:03 PM

All replies

  • A GUID looks like this: "754e8dc8-dbe5-4e49-be54-6c691750079c"

    You must use a real GUID and not just a string of numbers.


    \_(ツ)_/

    • Proposed as answer by Ed CrowleyMVP Sunday, June 11, 2017 12:18 AM
    Thursday, June 8, 2017 6:22 PM
  • You are of course correct. I surprise myself how stupid I can be.

    Friday, June 9, 2017 10:18 AM
  • So I did the following..

    $oct = "$FilteredNewobjWithNullsRemovedPart1"

    $oct1 = $oct.substring(0,2)
    $oct2 = $oct.substring(2,2)
    $oct3 = $oct.substring(4,2)
    $oct4 = $oct.substring(6,2)
    $oct5 = $oct.substring(8,2)
    $oct6 = $oct.substring(10,2)
    $oct7 = $oct.substring(12,2)
    $oct8 = $oct.substring(14,2)
    $oct9 = $oct.substring(16,4)
    $oct10 = $oct.substring(20,12)

    $strOut = "$oct4" + "$oct3" + "$oct2" + "$oct1" + "-" + "$oct6" + "$oct5" + "-" + "$oct8" + "$oct7" + "-" + "$oct9" + "-" + "$oct10"

    $Id = [GUID]($strOut)

    Sunday, June 11, 2017 7:45 PM
  • Where are you getting this GUID from?  It is a bi nary GUID and can be converted in one step:

    [guid]$binaryguid

    Just cast the array to a GUID.

    You cannot correctly convert a hex string to a GUID in most cases. It will not be the correct value.

    The output in AdsiEdit is just a string representation of a byte array.  You can get the GUID from any object as a GUID by just asking for it.

    PS C:\scripts> Get-AdComputer ws701 | select objectGUID
    
    objectGUID
    ----------
    8e4ddb8a-4d80-4f4c-8704-a18597e8b013

    Every object in AD has a GUID.  Some objects reference GUIDs as byte arrays which will be displayed in ADSIEdit as hex pairs one per byte.

    PS C:\scripts> $guid = Get-AdComputer ws701 | select -expand objectGUID
    PS C:\scripts> $bytearray = $guid.ToByteArray()
    PS C:\scripts> [guid]$bytearray
    
    Guid
    ----
    8e4ddb8a-4d80-4f4c-8704-a18597e8b013

    What object property are you trying to convert?

    For Exchange objects get the object and reference its "objectGuid" property.

    If ExchOnline then see this article: https://blogs.msdn.microsoft.com/harishck/2017/02/26/update-msexcharchiveguid-in-bulk-from-exchange-online-to-on-premise-ad/

    With objects there is almost never any need to play with strings.


    \_(ツ)_/



    • Edited by jrv Sunday, June 11, 2017 8:08 PM
    • Marked as answer by Andrew_Stevens Sunday, June 11, 2017 8:29 PM
    Sunday, June 11, 2017 8:03 PM
  • Note also that the order of the hex bytes is not the order of the guid results.  It is inverted.


    \_(ツ)_/

    Sunday, June 11, 2017 8:11 PM
  • To correctly convert a hex string to a byte array we would do this:

    $hex = '5C669E441173CF4394995E43EC8ED9ED'
    [byte[]]$bytes = for($i = 0; $i -lt $hex.Length; $i += 2) {
    	$s = $hex.SubString($i, 2)
    	[convert]::ToByte($s, 16)
    }
    [guid]$bytes

    Of course this does not correctly adjust for byte order in all cases which is dependent on the system the hex string was converted from.


    \_(ツ)_/


    • Edited by jrv Sunday, June 11, 2017 8:39 PM
    Sunday, June 11, 2017 8:39 PM