以 ip 地址为目标的 Powershell 远程处理

标签 powershell remoting powershell-remoting

我在 Server 2008 R2 上成功启用了 PSRemoting。 我可以使用主机名作为目标从同一网络内执行远程 pssession。

当我尝试从任何计算机(在网络内或从另一个网络(例如通过 VPN))使用 IP 地址作为目标时,我失败了。 我希望能够通过 VPN 连接使用远程处理,但由于无法解析主机名,因此必须使用 IP 地址。

我不想将名称添加到我的主机文件中,因为我们客户的其他一些服务器具有相同的 dns 名称,并且我不想删除和插入名称 IP 地址-一次又一次的联想。

我希望有人能告诉我如何允许通过IP调用psremoting-target。

编辑:更具体地说,我希望能够运行此:

Enter-PSSession -Computername 192.168.123.123 -credentials $cred 

但只有将主机名传递给“-Computername”时,我才能运行该命令

编辑2:
当我尝试使用 IP 而不是主机名(来自内部网络)登录时,出现以下错误消息:

Enter-PSSession : Connecting to remote server failed with the following error message : The WinRM client cannot process
 the request. Default authentication may be used with an IP address under the following conditions: the transport is HT
TPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure T
rustedHosts. Note that computers in the TrustedHosts list might not be authenticated. For more information on how to se
t TrustedHosts run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting
 Help topic.

编辑3:
我知道 WSMan 的受信任主机设置,但这似乎不是问题。它已经设置为“*”(我在启用远程处理后立即执行此操作),但我仍然无法使用 ip 作为目标计算机名连接到该服务器,但我可以使用主机名作为目标计算机名进行连接。似乎 IIS 中的绑定(bind)之类的东西会阻止监听器监听针对 ip 号而不是主机名的请求。但没有安装IIS。我不知道去哪里寻找这样的设置。

2011-07-12更新:
好的,我认为 trusthosts-setting 不是问题,因为我可以通过主机名从我们的 DC 连接,但如果我使用计算机参数的目标 IP 地址则不行。
我想,问题一定出在听者身上。也许监听器不会接受针对目标 IP 而不是目标主机名的请求。但我不知道如何改变它。

最佳答案

错误消息已为您提供了大部分所需内容。这不仅仅涉及 TrustedHosts 列表;还涉及 TrustedHosts 列表。也就是说,为了使用具有默认身份验证方案的 IP 地址,您还必须使用 HTTPS(默认情况下未配置)并提供显式凭据。我可以告诉您至少没有使用 SSL,因为您没有使用 -UseSSL 开关。

请注意,默认情况下未配置 SSL/HTTPS - 这是您必须执行的额外步骤。您不能只添加 -UseSSL。

默认的身份验证机制是 Kerberos,它希望看到 AD 中出现的真实主机名。不是 IP 地址,也不是 DNS CNAME 昵称。有些人会启用基本身份验证,这种身份验证不太挑剔 - 但您还应该设置 HTTPS,因为否则您会以明文形式传递凭据。 Enable-PSRemoting 仅设置 HTTP。

将名称添加到主机文件将不起作用。这不是名称解析的问题;而是名称解析的问题。它是关于计算机之间如何进行相互验证的。

此外,如果此连接涉及的两台计算机不在同一个 AD 域中,则默认身份验证机制将不起作用。有关配置非域和跨域身份验证的信息,请阅读“help about_remote_troubleshooting”。

来自 http://technet.microsoft.com/en-us/library/dd347642.aspx 的文档

HOW TO USE AN IP ADDRESS IN A REMOTE COMMAND
-----------------------------------------------------
    ERROR:  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.

The ComputerName parameters of the New-PSSession, Enter-PSSession and
Invoke-Command cmdlets accept an IP address as a valid value. However,
because Kerberos authentication does not support IP addresses, NTLM
authentication is used by default whenever you specify an IP address. 

When using NTLM authentication, the following procedure is required
for remoting.

1. Configure the computer for HTTPS transport or add the IP addresses
   of the remote computers to the TrustedHosts list on the local
   computer.

   For instructions, see "How to Add a Computer to the TrustedHosts
   List" below.


2. Use the Credential parameter in all remote commands.

   This is required even when you are submitting the credentials
   of the current user.

关于以 ip 地址为目标的 Powershell 远程处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6587426/

相关文章:

.net - 为什么 IpcChannel 告诉我, "Cannot open an anonymous level security token?"

powershell - 如何在powershell远程 session (powershell)中编辑文件

powershell - “远程注册表(RemoteRegistry)”无法启动

visual-studio - 如何在 Visual Studio 2008 中调试透明代理实例?

c# - 具有客户端激活对象的应用程序域中静态对象的远程生命周期

powershell - 在远程Windows Server上创建本地用户并添加到管理员组

PowerShell 访问被拒绝。 PSRemotingTransportException +fullyQualifiedErrorId : PSSessionStateBroken

powershell - 按文件名查找并替换给定日期范围内文件中的字符串

powershell - 将负数设置为零Powershell

windows - 如何强制 systeminfo 输出为英文以使用 Powershell 解析它?