Character encoding in powershell

Welcome Forums General PowerShell Q&A Character encoding in powershell

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
4 years, 6 months ago.

  • Author
    Posts
  • #18553

    Participant
    Points: 1
    Rank: Member

    Anyone know the technique to correctly encode a string value in the format required by the Active Directory unicodePwd attribute? In other languages, this is pretty simple but I am missing something when using PowerShell?

  • #18554

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    That attribute is supposed to be a one-way hash (OWF) of the password, usable by downlevel (NT) systems, meaning it isn't a clear-text password. You're able to generate the correct OWF hash?

    If so, http://stackoverflow.com/questions/1056692/how-to-encode-unicode-character-codes-in-a-powershell-string-literal may be helpful.

  • #18560

    Participant
    Points: 1
    Rank: Member

    Well, not one-way, http://msdn.microsoft.com/en-ca/library/cc223248.aspx but none the less I am still unable to create a string that the DSA accepts:(

    Thanks!

  • #18715

    Participant
    Points: 1
    Rank: Member

    Hey Dave,

    Problem was related to code elsewhere, so the process is (as expected) like other languages:

    # Surround password in quotes (I needed a random password).
    $pwdString = '"{0}"' -f [guid]::NewGuid()

    # Obtain byte array from UTF-16LE encoded string.
    $encoding = [System.Text.Encoding]::GetEncoding('utf-16')
    [byte[]]$pwdBin = $encoding.GetBytes($pwdString)

    $stringEncoded = [Convert]::ToBase64String($pwdBin)

    That encoded value can be applied directly to the field.

The topic ‘Character encoding in powershell’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort