Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 747 Bytes

File metadata and controls

26 lines (20 loc) · 747 Bytes
pid 104
author Joel Bennett
title Read-HostMasked
date 2008-01-08 13:01:07 -0800
format posh
parent 0

Read-HostMasked

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

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;
}