Windows PowerShell


Windows PowerShell Get-Credential

PowerShell Get-CredentialWindows PowerShell Credential

PowerShell's get-Credential disappointed me.  I had hoped that this cmdlet would 'capture' my current credentials and encrypt them.  I now realize that get-Credential has a different purpose, which is to supply a dialog box for us to enter an alternative name and its password.

Topics for PowerShell Get-Credential

 ♣

PowerShell Get-Credential Example

A typical scenario for get-Credential, is when you are logged on as ordinary user and you need the credentials of an administrator so that the rest of the PowerShell script will execute successfully.  You may wish to append the -credential parameter followed by the name of a user account with more rights.

get-Credential -credential administrator
# A dialog box should appear populated with administrator
# See screenshot above

Note 1:  Most people put the user name "administrator" in double quotes.

Note 2:  As with all PowerShell nouns, remember that credential is singular.

Get-Credential As a Foundation for Other Cmdlets

The point of this example, in fact the only reason for using get-Credential is that the current user has insufficient privileges to run the rest of the PowerShell commands.

$Cr = Get-Credential -credential Administrator
Get-WmiObject Win32_Service -Computer ExchSrv -Credential $Cr

Note 1:  If you were already logged on with administrative privileges on the network computer it would be pointless to add the get-Credential code.

Note 2: This command won't work on your network unless you change -Computer ExchSrv to the hostname of a machine on your network.  Incidentally, if the command still does not work try disabling the firewall.Windows PowerShell consolePrompting Credential

-ConsolePrompting

The idea of adding this registry setting is twofold, firstly to suppress the credential dialog box, secondly so that you can type the username and password at the command line.

While this technique just would not work for me in Windows Server 2008 PowerShell v 2.0 (CTP3); it DID WORK in WINDOWS 7.

This is one way of adding the registry key:

$key = "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds"
Set-ItemProperty $key ConsolePrompting True

You have to imagine that you are now at the PowerShell command prompt.
When you type:

get-Credential

You should get a line saying:

Supply values for the following parameters:
Credential
User:

Then when you type Administrator this is what you see:

Supply values for the following parameters:
Credential
User: Administrator
Password for    Administrator

Note 1:  I say again, this did not work in Windows Server 2008, even though I could see and control the ConsolePrompting key in the registry at:  HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds. And the value was set to 'True'.

Note 2: The above technique did work in Windows 7.  I kept it simple just launched the PowerShell command line and typed: get-Credential.   Incidentally, there is no need to type a -ConsolePromting switch.

# This is wrong
get-Credential -consolePrompting

Guy Recommends: SolarWinds Engineer's Toolset v10Engineer's Toolset v10

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and the tools teaches me more about how the system literally operates.

There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.  Download your copy of the Engineer's Toolset v 10

Summary of Windows Get-Credential

The dialog box says it all.  If a PowerShell script needs elevated privileges - administrative rights, then include the get-Credential code to trap the relevant information.

See more PowerShell examples for Shutdown commands

PowerShell Home  • Syntax  • Stop-Computer  • Restart Computer  • Get-Credential

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.