我正在尝试使用应答文件运行Invoke-Command到用户凭据,但我似乎无法让它完成运行。我正在使用本地管理员帐户,因此域名中没有任何内容。这是我所拥有的和错误:
$Username = "$Env:Computername\admin"
$Pass = ConvertTo-SecureString "12345" -AsPlainText -Force
$User = New-Object Management.Automation.PSCredential($UserName, $Pass)
Invoke-Command -ComputerName $Env:Computername -Credential $User -ScriptBlock {
$Path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
$Name = 'DontDisplayLastUserName'
Set-ItemProperty -path $Path -name $Name -value 0
}
错误:
[computer] Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: There are curren
tly no logon servers available to service the logon request.
非常感谢任何帮助。
工作解决方案:
$Username = "$Env:Computername\admin"
$Pass = ConvertTo-SecureString "12345" -AsPlainText -Force
$User = New-Object Management.Automation.PSCredential($UserName, $Pass)
Invoke-Command -ComputerName localhost -Credential $User -ScriptBlock {
$Path = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
$Name = 'DontDisplayLastUserName'
Set-ItemProperty -path $Path -name $Name -value 0
}
答案 0 :(得分:1)
我终于找到了问题,随便打了我一下。需要更改以下行。
之前:
Invoke-Command -ComputerName $Env:Computername
之后:
Invoke-Command -ComputerName localhost
没有localhost,它就像远程计算机那样看着它,不允许它访问。