Linux operating systems provide GUI or command line access from its first days. But Windows operating systems are generally managed with only GUI which is generally Remote Desktop. The changes in IT made mass management or orchestration a must for system administrators. Windows have created Powershell for detailed and efficient command line shell and tools. In order to use Powershell remotely we need to enable PSRemoting in target systems. Without enabling it we can not use powershell remote commands like Invoke-Command
.
Linux操作系统从开始就提供GUI或命令行访问。 但是Windows操作系统通常仅使用GUI(通常是远程桌面)进行管理。 IT方面的变化使系统管理员必须进行大规模管理或编排。 Windows已创建Powershell,用于提供详细而有效的命令行Shell和工具。 为了远程使用Powershell,我们需要在目标系统中启用PSRemoting。 如果不启用它,我们将无法使用Powershell远程命令,例如Invoke-Command
。
客户端出现错误 (Error Appeared In Client)
We may get an error in a red ink like below in the client side powershell. This generally means that remote system do not configured to accept Powershell remote access.
如下图所示,我们可能会在客户端Powershell中出现红色墨水错误。 通常,这意味着远程系统未配置为接受Powershell远程访问。
-
+ CategoryInfo : OpenError: (:) [], PSRemotingTransportException
-
+ FullyQualifiedErrorId : PSSessionStateBroken
PSRemotingTransportException PSRemotingTransportException
检查PSRemoting的状态 (Check Status of PSRemoting)
Another way to check whether PS remoting is enabled is running following command in the remote system.
检查PS远程处理是否已启用的另一种方法是在远程系统中运行以下命令。
PS> Get-PSSessionConfiguration
Check Status of PSRemoting 检查PSRemoting的状态
As we can see there is detailed configuration about PSRemoting. This configuration is done according to Powershell version and user types.
我们可以看到有关于PSRemoting的详细配置。 此配置根据Powershell版本和用户类型完成。
启用PSRemoting (Enable PSRemoting)
Now most important part. We will enable the PSRemoting in order to able to run Remote commands using PSRemoting. We will use following command with -force
option to prevent some warnings.
现在最重要的部分。 我们将启用PSRemoting,以便能够使用PSRemoting运行远程命令。 我们将使用带有-force
选项的以下命令来防止某些警告。
PS> Enable-PSRemoting -Force
Enable PSRemoting 启用PSRemoting
We can again check like in previous step the status of the PSRemoting.
我们可以像上一步一样再次检查PSRemoting的状态。
将客户端主机添加到受信任的主机 (Add Client Host To The Trusted Hosts)
If previous steps do not works try following command by changing IP address with the remote system.
如果前面的步骤不起作用,请尝试通过更改远程系统的IP地址来执行以下命令。
PS> winrm s winrm/config/client '@{TrustedHosts="192.168.122.167"}'