Los*_*ter 23 .net powershell powershell-2.0 system.management
如何在没有密码的PSCredential中创建实例?
我试过的事情:
Get-Credential
错误:无法处理参数,因为参数"password"的值为null
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $null)
错误:ConvertTo-SecureString:无法将参数绑定到参数'String',因为它为null.
$mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force))
错误:ConvertTo-SecureString:无法将参数绑定到参数'String',因为它是一个空字符串.
Los*_*ter 37
解:
$mycreds = New-Object System.Management.Automation.PSCredential
("username", (new-object System.Security.SecureString))
Run Code Online (Sandbox Code Playgroud)