【发布时间】:2014-01-31 02:09:06
【问题描述】:
在我的程序中,我需要在参数中询问用户密码:
[Cmdlet(VerbsCommon.Get, "MyTest"]
public class GetMyTest : PSCmdlet
{
[Parameter(Mandatory=true)]
public ? Password { get; set;}
}
我不知道密码的正确类型是什么。在另一个问题中: How does one securely handle passwords in a custom written PowerShell cmdlet?
接受的答案要求在代码中使用 read-host,但我必须使用参数来询问此字段。
我也尝试使用 SecureString 作为密码,但我无法为该参数提供 SecureString,因为它将被自动接受为字符串,而不是安全字符串。
有什么办法可以实现如下用法:
Get-MyTest -Password ***** (where I actually type in 'abcde' but the input is masked.)
【问题讨论】:
标签: c# powershell powershell-cmdlet