如何通过 powershell 远程连接到 Hyper-V 服务器以重新启动不在同一域中的虚拟机

如何通过 powershell 远程连接到 Hyper-V 服务器以重新启动不在同一域中的虚拟机

我尝试使用的机器未加入域(不会加入),并且希望能够使用 PowerShell 脚本远程重启 VM(pfSense)。

我在尝试测试与服务器的连接时不断收到此错误。

PS C:\WINDOWS\system32> Get-VM –computername 'LAB1' | Where { $_.State –eq 'Running' }
Get-VM : The operation on computer 'LAB1' failed: The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or 
the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by 
running the following command: winrm help config.

我尝试过这个:

winrm set winrm/config/client '@{TrustedHosts="DESKTOP-K2GD11M"}'
Enable-PSRemoting -Force

但仍然出现错误。

我也确实检查过get-item wsman:\localhost\Client\TrustedHosts并且添加了主机名或计算机名。

答案1

从您的域计算机尝试执行以下操作:(这不使用 Powershell Remoting)

$cred = Get-Credential \LAB1\Username
Get-VM -Computername LAB1 -Credential $cred |  Where { $_.State –eq 'Running' }

其中用户名是可以访问您的工作组的帐户,LAB1 是工作组。

您将看到一个对话框,提示您输入 LAB1\Username 的密码

现在,您需要做的是让您的客户端机器(域)信任服务器(工作组)。

您可以使用

winrm set winrm/config/client '@{TrustedHosts="LAB1"}'

或者

set-item wsman:\localhost\Client\TrustedHosts -value LAB1 -concatenate

在您的台式机上。

然后在测试时,确保您已包含有权访问目标服务器的凭据:

$cred = Get-Credential \LAB1\Username
Get-VM –Computername 'LAB1' -Credential $cred | Where { $_.State –eq 'Running' }

相关内容