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

4 years, 6 months ago.

  • Author
  • #18553

    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

    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, may be helpful.

  • #18560

    Points: 1
    Rank: Member

    Well, not one-way, but none the less I am still unable to create a string that the DSA accepts:(


  • #18715

    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