Sunday, 5 February 2017

SecureString in PowerShell


If you want to read secure string from a prompt, do the following:

$mySecureString = Read-Host 'Enter the string' -AsSecureString


To convert the SecureString to string, do the following:

$string= [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($mySecureStrring))