使用HTTP方式远程连接PowerShell

借助Windows PowerShell,我们可以像管理Linux一样使用命令行来远程管理Windows服务器。但是默认情况下,我们只能在域环境中使用PowerShell Remoting。如果是通过互联网远程连接到Windows服务器,则必须使用SSL(HTTPS)——这就意味着必须在远程服务器和客户端上配置证书,真心麻烦。虽然这些手段都是为了安全考虑,不过也确实给用户带来诸多不便。

其实,PowerShell Remoting是支持HTTP协议的(完全不需要配置证书):

首先在服务器上开启TCP 5985端口(操作系统防火墙和外部防火墙都要允许这个端口通过),这是PowerShell Remoting HTTP模式下使用的端口。

然后在服务器上以管理员身份运行PowerShell,执行以下命令:

#开启远程管理并跳过网络检查
Enable-PSRemoting -SkipNetworkProfileCheck -Force

#设置信任主机,允许所有客户端管理本服务器
Set-Item WSMan:localhostClientTrustedHosts -Value "*" -Force

在客户端上以管理员身份运行PowerShell,运行以下命令:

Set-Item WSMan:localhostClientTrustedHosts -Value "*" -Force

经过上述步骤,就可以连接到远程的Windows服务器执行Powershell操作啦。

$cred = Get-Credential
Enter-PSSession -ComputerName 服务器IP地址 -Credential $cred
原文地址:https://www.cnblogs.com/hunterxue/p/5319317.html