PowerShell多个PSCredential提示

时间:2016-03-07 00:23:25

标签: security powershell

我有一个包含以下参数的powershell脚本:

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

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

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

如何向用户说明他们输入的凭据是哪一个?

1 个答案:

答案 0 :(得分:1)

我自己找到答案,我可以做到以下

    [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'