简体   繁体   English

PowerShell 多个 PSCredential 提示

[英]PowerShell Multiple PSCredential Prompts

I have a powershell scripts with the following parameters:我有一个带有以下参数的powershell脚本:

        [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?我怎样才能让用户清楚他们输入的凭据是哪一个?

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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM