Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 创建没有密码的PSCredential_.net_Powershell_Powershell 2.0_System.management - Fatal编程技术网

.net 创建没有密码的PSCredential

.net 创建没有密码的PSCredential,.net,powershell,powershell-2.0,system.management,.net,Powershell,Powershell 2.0,System.management,如何创建没有密码的PSCredential实例?(无需手动填写无密码的Get Credential对话框,这是用于无人值守运行的。) 我尝试过的事情: $mycreds=New Object System.Management.Automation.PSCredential(“用户名”,$null) 错误:无法处理参数,因为参数“password”的值为空 $mycreds=New Object System.Management.Automation.PSCredential(“用户名”,(C

如何创建没有密码的PSCredential实例?(无需手动填写无密码的
Get Credential
对话框,这是用于无人值守运行的。)

我尝试过的事情:

  • $mycreds=New Object System.Management.Automation.PSCredential(“用户名”,$null)
    错误:无法处理参数,因为参数“password”的值为空

  • $mycreds=New Object System.Management.Automation.PSCredential(“用户名”,(ConvertTo SecureString$null-AsPlainText-Force))
    错误:ConvertTo SecureString:无法将参数绑定到参数“String”,因为它为null

  • $mycreds=New Object System.Management.Automation.PSCredential(“用户名”,(ConvertTo SecureString”“-AsPlainText-Force))
    错误:ConvertTo SecureString:无法将参数绑定到参数“String”,因为它是空字符串

  • 解决方案:

    $mycreds = New-Object System.Management.Automation.PSCredential 
                  ("username", (new-object System.Security.SecureString))
    

    使用Get-Credential cmdlet,当出现凭据对话框时,不要键入密码

    $cred = Get-Credential pebrian27
    $cred.GetNetworkCredential() | select UserName,Password
    
    UserName   Password
    --------   --------
    pebrian27
    

    -1-出现一个对话框,您没有输入内容,这与OP要求的内容无关。OP也给出了一个正确的答案,不需要这个答案。可能有不止一个解决方案,我看不出OP明确要求不使用cmdlet的地方。我不是说cmdlet。当然,您可以使用cmdlet(没有cmdlet的powershell!!)我说的是手动干预,在出现对话框时,您不需要输入密码就可以返回。这不是一个切实可行的解决办法。每次脚本运行时,您希望得到该对话框并返回?我建议您再次阅读该问题。这里面没有关于人工干预的内容。@Shay Levy-我不想看到凭证提示。但是,是的,我应该明确指出,Hi@EugeneO希望你能帮助我解决这个tksPowerShell太复杂了,没有什么愚蠢的问题。令人恼火的是,你必须使用和空密码以及填充密码来处理这两个案例。ConvertToSecureString毫无用处:“无法将参数绑定到参数‘String’,因为它是一个空字符串。”。