如何在PSCredential中创建没有密码的实例?
我尝试的事情:
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $null)
错误:无法处理参数,因为参数“password”的值为null
$mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force))
错误:ConvertTo-SecureString:无法将参数绑定到参数'String',因为它为null。
$mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "" -AsPlainText -Force))
错误:ConvertTo-SecureString:无法将参数绑定到参数'String',因为它是一个空字符串。
答案 0 :(得分:31)
解决方案:
$mycreds = New-Object System.Management.Automation.PSCredential
("username", (new-object System.Security.SecureString))
答案 1 :(得分:-2)
使用Get-Credential cmdlet,出现凭据对话框时,不要输入密码
$cred = Get-Credential pebrian27
$cred.GetNetworkCredential() | select UserName,Password
UserName Password
-------- --------
pebrian27