Skip to content

Instantly share code, notes, and snippets.

@alex4rks
Created August 1, 2018 10:00
Show Gist options
  • Select an option

  • Save alex4rks/1efd0c21e34512e68270eff6097ba15e to your computer and use it in GitHub Desktop.

Select an option

Save alex4rks/1efd0c21e34512e68270eff6097ba15e to your computer and use it in GitHub Desktop.
$Secure = Read-Host -AsSecureString
# input password: **********
$hash = ConvertFrom-SecureString -SecureString $Secure
# get hash
$password = ConvertTo-SecureString -String $hash
# use hashed password in cmdlets
New-LocalUser -User $user -password $password -PasswordNeverExpires:$true -AccountNeverExpires:$true
###
### decrypt password
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$DecodedPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment