Securely get input from a user using PowerShell

Get input in a secure fashion using PowerShell

John Savill

March 6, 2016

1 Min Read
Securely get input from a user using PowerShell

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

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like