Prompting for Passwords

If you need to prompt for a secret password and do not want it to be visible while entered, you should use Get-Credential. This cmdlet returns a credential object, which contains the entered password in encrypted format. You should then call GetNetworkCredential() to un-encrypt it to plain text:

$cred = Get-Credential SomeUserName
$cred.Password
System.Security.SecureString
$cred.GetNetworkCredential()
UserName Password Domain
-------- -------- ------
SomeUserName secret
$cred.GetNetworkCredential().Password
secret

Twitter This Tip! ReTweet this Tip!


Posted Sep 22 2010, 08:01 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.