# encoding: ascii
# api: powershell
# title: Read-HostMasked
# description: Read a string from the host using SecureString input, but output it as a plain string for use in functions that don’t accept SecureStrings
# version: 0.1
# type: function
# author: Joel Bennett
# license: CC0
# function: Read-HostMasked
# x-poshcode-id: 104
# x-archived: 2017-04-30T12:48:39
# x-published: 2008-01-08T21:01:00
#
#
function Read-HostMasked([string]$prompt="Password") {
$password = Read-Host -AsSecureString $prompt;
$BSTR = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password);
$password = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($BSTR);
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR);
return $password;
}