2

#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.

Filed in: Columns, Tips and Tricks Tags: , , ,

One Pingback/Trackback

2 Responses to "#PSTip Get-Credential at the command line"

  1. Josh A says:

    Great tip! I had wondered why I experienced that behavior on my server but not my laptop. now it makes more sense. Thanks for sharing.

Leave a Reply

Submit Comment

© 4043 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: