问题描述
假设我有一个自定义的PowerShell Cmdlet,它导出数据并使用密码加密它。 [Cmdlet(VerbsData.Export ,SampleData)]
public class ExportSampleData:PSCmdlet
{
[Parameter(Mandatory = true)]
public string Password
{
get;
set;
}
/ *其他参数* /
}
如何妥善处理密码?例如,当管理员在控制台中键入值时,我想禁止显示该值。其他选项包括读取包含加密密码的文件。
我知道PSCredential,但需要一个用户名,在这种情况下没有意义。
如果您只想获取密码,可以使用
code> -asSecureString 参数中的code> Read-Host cmdlet。
此参数屏蔽输入。
Assume I have a custom PowerShell Cmdlet that exports data and encrypts it using a password.
[Cmdlet(VerbsData.Export, "SampleData")]
public class ExportSampleData : PSCmdlet
{
[Parameter(Mandatory = true)]
public string Password
{
get;
set;
}
/* additional parameters */
}
How does one appropriately handle the passwords securely? For example, I'd like to prevent the value from being displayed when the administrator types it in the console. Other options include reading a file that contains an encrypted password.
I'm aware of PSCredential but that requires a user name which makes no sense in this scenario.
If you only want to obtain the password, you can use
Read-Host
cmdlet with the–asSecureString
parameter.
This parameter mask the input.
这篇关于如何安全地处理自定义编写的PowerShell cmdlet中的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!