CmdID / PowerShell / Cmdlets / Get
Get-Credential
Gets a credential object based on a user name and password. PowerShell reference
From the PowerShell reference 3 parameters
What it does
Gets a credential object based on a user name and password. The Get-Credential cmdlet creates a credential object for a specified user name and password. You can use the credential object in security operations. Beginning in PowerShell 3.0, you can use the Message parameter to specify a customized message on the dialog box that prompts the user for their name and password. The Get-Credential cmdlet prompts the user for a password or a user name and password. By default, an authentication dialog box appears to prompt the user. However, in some host programs, such as the PowerShell console, you can prompt the user at the command line by changing a registry entry. For more information about this registry entry, see the notes and examples.
Get-Credential [-Credential] <PSCredential> [<CommonParameters>]Get-Credential -Message <String> [[-UserName] <String>] [<CommonParameters>]
Example 1
$c = Get-CredentialIdentifyExample 2
$c = Get-Credential -Credential User01
$c.Username
User01IdentifyExample 3
$Credential = $Host.UI.PromptForCredential(
"Need credentials", "Please enter your user name and password.", "", "NetBiosUserName")IdentifyExample 4
Set-ItemProperty 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds' -Name ConsolePrompting -Value $trueIdentifyExample 5
$User = "Domain01\User01"
$PWord = Read-Host -Prompt 'Enter a Password' -AsSecureString
$credentialParams = @{
TypeName = 'System.Management.Automation.PSCredential'
ArgumentList = $User, $PWord
}
$Credential = New-Object @credentialParamsIdentifyExample 6
$credentialParams = @{
Message = "Credential are required for access to the \\Server1\Scripts file share."
UserName = "Server01\PowerUser"
}
Get-Credential @credentialParamsIdentifyExample 7
Invoke-Command -ComputerName Server01 -ScriptBlock {Get-Credential Domain01\User02}IdentifyIts page in the reference: Get-Credential.
Parameters
-CredentialSpecifies a user name for the credential, such as User01 or Domain01\User01. The parameter name, -Credential, is optional.
When you submit the command and specify a user name, you're prompted for a password. If you omit this parameter, you're prompted for a user name and a password.
Starting in PowerShell 3.0, if you enter a user name without a domain, Get-Credential no longer inserts a backslash before the name.
Credentials are stored in a PSCredential object and the password is stored as a SecureString.
NOTE: For more information about SecureString data protection, see How secure is SecureString?.-MessageSpecifies a message that appears in the authentication prompt. This parameter is designed for use in a function or script. You can use the message to explain to the user why you are requesting credentials and how they will be used.
This parameter was introduced in PowerShell 3.0.-UserNameSpecifies a user name. The authentication prompt requests a password for the user name. By default, the user name is blank and the authentication prompt requests both a user name and password.
When the authentication prompt appears in a dialog box, the user can edit the specified user name. However, the user cannot change the user name when the prompt appears at the command line. When using this parameter in a shared function or script, consider all possible presentations.
This parameter was introduced in PowerShell 3.0.