尝试在远程计算机上调用 powershell 命令时出现错误

cmm*_*ser 2 powershell invoke powershell-2.0 powershell-remoting

machineName 尝试通过以下方式使用 invoke-command 执行脚本:

 Invoke-command -filepath C:\scripts\GettMembers.ps1 -computername "machinename" -credential $Getcredential 
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Connecting to remote server failed with the following error message : The WinRM client cannot process the request because the server name cannot be resolved. For more information, see the about_Remote_Troubleshooting Help topic.
Run Code Online (Sandbox Code Playgroud)

但我可以使用以下命令将计算机添加到本地计算机的受信任主机:

winrm set winrm/config/client `@{TrustedHosts="machineName"}' 
Run Code Online (Sandbox Code Playgroud)

Bry*_*ley 5

问题似乎是您的 DNS 不知道如何解析“machinename”。这不是 powershell 问题,而是系统配置问题。

您可以通过要求 powershell 解析计算机名称来验证这一点,如下所示:

$machine = "machinename"
[System.Net.Dns]::GetHostEntry($machine)
Run Code Online (Sandbox Code Playgroud)

如果出现错误,则意味着您正在使用无法解析的计算机名称(即:Windows 无法将“计算机名称”转换为 IP 地址)。这不是信任或权限的问题,而是您的计算机认为“machinename”不是网络上的有效计算机。

您是否尝试过使用完全限定的地址(例如:machinename.mycompany.com)?