Aaron Stainback
Aaron Stainback

Reputation: 3667

PowerShell Multiple PSCredential Prompts

I have a powershell scripts with the following parameters:

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [pscredential]
        $DatabaseCredential

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [pscredential]
        $Service1Credential

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [pscredential]
        $Service2Credential

How can I make it clear to the user which one they are entering the credentials for?

Upvotes: 1

Views: 100

Answers (1)

Aaron Stainback
Aaron Stainback

Reputation: 3667

Found the answer myself, I can do the following

    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [pscredential]
    $DatabaseCredential = Get-Credential -Message 'Database'

    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [pscredential]
    $Service1Credential = Get-Credential -Message 'Service1'

    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [pscredential]
    $Service2Credential = Get-Credential -Message 'Service2'

Upvotes: 1

Related Questions