# take a SecureString and get the entered plain text password # we are using a SecureString only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# fails: PS> Test-Password-Password test Test-Password : Cannot process argument transformation on parameter'Password'. Cannot convert the "test" value of type"System.String" to type"System.Security.SecureString".
# works PS> Test-Password-Password ("test" | ConvertTo-SecureString-AsPlainText-Force) You entered: test
# take a SecureString and get the entered plain text password # we are using a SecureString only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# use built-in masked input PS> Test-Password cmdlet Test-Password at command pipeline position 1 Supply values for the following parameters: Password: ****** You entered: secret
# use text-to-SecureString transformation attribute PS> Test-Password-Password secret You entered: secret