Securely get input from a user using PowerShell
Get input in a secure fashion using PowerShell
March 6, 2016
Q. How can I securely get input from a user using PowerShell?
A. It's typical to pass information to cmdlets as parameters however its also possible to read input from the user with:
$name = Read-Host "Who are you?"
If you wish to store a sensitive value that should not display to screen as its entered add -AsSecureString, for example:
$pass = Read-Host "What's your password?" -AsSecureString
If you later wanted to convert the secure string to plain text use:
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass))
Each week, John Savill answers all of your toughest tech questions about the worlds of Windows Server, Azure, and beyond. Read his past IT advice here, and email your questions to [email protected].
About the Author
You May Also Like