0

我正在尝试使用用户凭据的答案文件运行 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
} 
4

1 回答 1

1

我终于弄清楚了问题,随机打了我。需要更改以下行。

前:

Invoke-Command -ComputerName $Env:Computername

后:

Invoke-Command -ComputerName localhost

如果没有 localhost,它会将其视为远程计算机,并且不允许它访问。

于 2012-12-26T20:16:25.367 回答