混合域环境中的 WinRM





0/5 (0投票)
Windows 远程管理在相同域环境中工作得非常完美,但在混合域环境中存在一些需要注意的地方。
引言
Windows 远程管理在相同域环境中工作得非常完美,并且配置相对简单。当它有效时,它功能强大,提供了一种高度灵活的方式来安全地远程执行命令。
然而,当尝试在混合域环境中使用 WinRM,或者只有一台机器加入域时,问题就出现了。正如我发现的,这需要一些额外的配置步骤,如下所述。
启用远程管理
在相同域中的计算机之间启用 WinRM,只需在远程服务器上的提升权限的 PowerShell 控制台中运行以下命令即可。这将启用 WinRM 并配置防火墙,以便它可以接受传入的命令。
Enable-PSRemoting
完成此操作后,就可以按以下方式远程对机器执行命令了
Invoke-Command -ComputerName RM-SERVER -ScriptBlock {Get-Process}
此示例将使用 Get-Process
cmdlet 列出名为 RM-SERVER 的远程机器上的进程。
混合域
混合域环境需要一些额外的配置才能使其正常工作。为此,需要在远程服务器上执行以下命令。这将允许客户端服务器从不同的域进行身份验证,或使用本地于远程服务器的帐户进行身份验证。
New-Itemproperty -name LocalAccountTokenFilterPolicy
-path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -propertyType DWord -value 1
有了此配置,现在就可以使用显式凭据进行身份验证并远程执行命令了。
$credential = Get-Credential
Invoke-Command -ComputerName RM-SERVER -ScriptBlock {Get-Process} -Credential $credential
或者像下面所示,在脚本中显式创建凭据
$securePassword = ConvertTo-SecureString "Password" -AsPlainText -force
$credential = New-Object System.Management.Automation.PsCredential("domain\username",$securePassword)
Invoke-Command -ComputerName RM-SERVER -ScriptBlock {Get-Process} -Credential $credential
故障排除
WinRM 无法处理请求
小心,我为此花费了几个小时。无论我做什么,我一直收到以下错误。原来这是由远程服务器上运行的反病毒软件引起的,需要禁用它。
Connecting to remote server failed with the following error message :
WinRM cannot process the request. The following error occurred while using Kerberos authentication:
There are currently no logon servers available to service the logon request.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the
two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts
configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config.
For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken
受信任的主机
可以配置远程服务器以仅允许来自特定主机的命令。为此,在远程服务器上的提升权限的 PowerShell 控制台中运行以下命令。默认情况下,它设置为允许任何主机 (*)。
Set-item wsman:localhost\client\trustedhosts -value RM-Client1,RM-Client2
上面的行配置远程服务器,仅允许来自机器 RM-Client1 和 RM-Client2 的命令。
防火墙配置
WinRm 需要端口 5985 用于 http,或端口 5986 用于 https。Enable-PSRemoting
cmdlet 将自动配置 Windows 软件防火墙,但请确保这些端口在您的网络基础设施中可访问。