如何创建没有密码的PSCredential实例? (无需手动填写不带密码的Get-Credential
对话框,即可无人参与运行。)
我尝试过的事情:
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $null)
错误:无法处理参数,因为参数“password”的值为空$mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force))
错误:ConvertTo-SecureString:无法将参数绑定(bind)到参数'String',因为它为null。 $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "" -AsPlainText -Force))
错误:ConvertTo-SecureString:无法将参数绑定(bind)到参数'String',因为它是空字符串。 最佳答案
解:
$mycreds = New-Object System.Management.Automation.PSCredential
("username", (new-object System.Security.SecureString))
关于.net - 创建不带密码的PSCredential,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6839102/