学习WinServer必须学习powershell,学习powershell必须掌握远程管理服务器的方法,因此必须学会winrm来远程管理服务器
记录一些经常使用的winrm命令和错误
经常使用命令
//在Powershell中执行
Set-Item WSMan:\localhost\client\TrustedHosts –Value "win-2ickeabl4tr.test.com" -force
//在Powershell中执行
Set-Item wsman:\localhost\client\trustedhosts *
//在Cmd中执行
winrm set winrm/config/client @{TrustedHosts="RemoteComputerName"}
//在Cmd中执行
winrm set winrm/config/client @{TrustedHosts="win-2ickeabl4tr"}
//在powershell中执行
Enter-PSSession 10.10.2.11 -Credential test\administrator
//在powershell中执行
Enter-PSSession win-2ickeabl4tr.test.com -Credential administrator
错误1:
{"链接到远程服务器 win-2ickeabl4tr.test.com 失败,并显示如下错误消息: WinRM 没法处理该请求。使用 Kerberos 身份验证时发生错误代码为 0x80090311 的如下错误: 目前没有可用的登陆服务器,没法处理登陆请求。 \r\n 可能的缘由为:\r\n -指定的用户名或密码无效。\r\n -未指定身份验证方法和用户名时,使用了 Kerberos。\r\n -Kerberos 接受域用户名,但不接受本地用户名。\r\n -远程计算机名和端口的服务主体名称(SPN)不存在。\r\n -客户端和远程计算机位于不一样的域中,而且两个域之间没有信任关系。\r\n 检查上述问题以后,尝试如下操做:\r\n -检查事件查看器中与身份验证有关的事件。\r\n -更改身份验证方法;将目标计算机添加到 WinRM TrustedHosts 配置设置中或 使用 HTTPS 传输。\r\n 请注意,TrustedHosts 列表中的计算机可能未通过身份验证。\r\n -有关 WinRM 配置的详细信息,请运行如下命令: winrm help config。 有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。"}
服务器端配置winrm命令
//快速在服务端运行winrm
c:\> winrm quickconfig
//查看winrm的运行状况
c:\> winrm e winrm/config/listener
//查看winrm的配置
c:\> winrm get winrm/config
// 将service中的allowUnencrypted设置为true,容许未加密的通信
c:\> winrm set winrm/config/service @{AllowUnencrypted="true"}
//将client中的基自己份验证设置为true,容许
c:\> winrm set winrm/config/client/auth @{Basic="true"}
// 将client中的allowUnencrypted设置为true,容许未加密的通信
c:\> winrm set winrm/config/client @{AllowUnencrypted="true"}
// 设置主机信任的客户端地址,这里host1,2,3能够填你所在的客户端机器的ip或者主机名
c:\> winrm set winrm/config/client @{TrustedHosts="host1, host2, host3"}
//这个没尝试过
c:\> winrm identify -r:http://winrm_server:5985 -auth:basic -u:user_name -p:password -encoding:utf-8