#PSTip Get-Credential at the command line

PowerShell’s Get-Credential cmdlet lets us create a secure credential object for a specified user name and password using a UI dialog:

PS> Get-Credential shay

There’s a way of replacing the UI and collect the credentials via the command line. You need to be an administrator to do that and the console must be elevated (e.g “Run as Admin”).

The change involves adding a registry value to the HKLM hive:

$key = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds"
Set-ItemProperty -Path $key -Name ConsolePrompting -Value $true

You add the ConsolePrompting value to the above path and set its data to $true. From now on, all Get-Credential calls will look like this:

PS> Get-Credential shay

Windows PowerShell Credential Request
Enter your credentials.
Password for user shay: ********

To bring back the UI dialog, set the value to $false or remove it all altogether. Note that this trick doesn’t have any effect in the ISE.

Share on:
comments powered by Disqus