Get-Credential

 

SYNOPSIS

Gets a credential object based on a user name and password.

 

SYNTAX

Get-Credential [-credential] <PSCredential> [<CommonParameters>]

 

DETAILED DESCRIPTION

The Get-Credential cmdlet creates a credential object for a specified username and password. You can use the credential object in security operations.

 

PARAMETERS

 

-credential <PSCredential>

Specifies a user name for the credential, such as "User01" or "Domain01\User01". The parameter name ("-Credential") is optional.

 

When you enter the command, you will be prompted for a password.

 

If you omit this parameter, you will be prompted for a user name and a password.

 

Required?

true

Position?

1

Default value

null

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

None

 

RETURN TYPE

CredentialObject

 

NOTES

 

For more information, type "Get-Help Get-Credential -detailed". For technical information, type "Get-Help Get-Credential -full".

 

You can use the PSCredential object that Get-Credential creates in cmdlets that request user authentication, such as those with a Credential parameter.

 

The Credential parameter is not supported by the providers that are installed with Windows PowerShell. However, you can use the Credential parameter with Get-WmiObject, because it calls .NET directly.

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

$c = Get-Credential

 

This command gets a credential object and saves it in the $c variable.

 

When you enter the command, a dialog box appears requesting a user name and password. When you enter the requested information, the cmdlet creates a PSCredential object representing the credentials of the user and saves it in the $c variable.

 

You can use the object as input to cmdlets that request user authentication, such as those with a Credential parameter. However, the providers that are installed with Windows PowerShell do not support the Credential parameter.

 

EXAMPLE 2

 

$c = Get-Credential

 

Get-WmiObject Win32_DiskDrive -ComputerName Server01 -Credential $c

 

These commands use a credential object from Get-Credential to authenticate a user on a remote computer so they can use Windows Management Instrumentation (WMI) to manage the computer.

 

The first command gets a credential object and saves it in the $c variable. The second command uses the credential object in a Get-WmiObject command. This command gets information about the disk drives on the Server01 computer.

 

EXAMPLE 3

 

Get-WmiObject Win32_BIOS -ComputerName Server01 '

-Credential (get-credential Domain01\User01)

 

This command shows how to include a Get-Credential command in a Get-WmiObjectcommand.

 

This command uses the Get-WmiObject cmdlet to get information about the BIOS on the Server01 computer. It uses the Credential parameter to authenticate the user, Domain01\User01, and a Get-Credential command as the value of the Credential parameter.

 

RELATED LINKS

Get-WmiObject