The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PSHostUserInterface.PromptForCredential Method (String, String, String, String, PSCredentialTypes, PSCredentialUIOptions)


Updated: April 27, 2016

Applies To: Windows PowerShell

When overridden in a derived class, prompts the user for credentials by using a specified prompt window caption, prompt message, user name and target name, credential types allowed to be returned, and UI behavior options.

Namespace:   System.Management.Automation.Host
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

public abstract PSCredential PromptForCredential(
	string caption,
	string message,
	string userName,
	string targetName,
	PSCredentialTypes allowedCredentialTypes,
	PSCredentialUIOptions options


Type: System.String

The caption for the message window.

Type: System.String

The text of the message.

Type: System.String

The user name whose credential is to be prompted for. If this parameter set to null or an empty string, the function will prompt for the user name first.

Type: System.String

The name of the target for which the credential is collected.

Type: System.Management.Automation.PSCredentialTypes

A bitwise combination of the PSCredentialTypes enumeration values that identify the types of credentials that can be returned.

Type: System.Management.Automation.PSCredentialUIOptions

A bitwise combination of the PSCredentialUIOptions enumeration values that identify the UI behavior when it gathers the credentials.

Return Value

Type: System.Management.Automation.PSCredential

A PSCredential object that contains the credentials for the target.

Exception Condition

The host can throw this exception when it cannot complete an operation.


If this method is not implemented, the host should throw a "not implemented" exception when it receives this call.


The host can throw this exception when an error occurs while a command is running.

Return to top

Community Additions