PowerShell远程控制出现“拒绝访问”错误

29

我想使用PowerShell Remoting来检查远程域中某个服务器的磁盘大小,但我运行的命令无法正常工作。

情况如下:

  • 源服务器在A域
  • 目标服务器在B域
  • 这些域之间没有建立信任关系

B域中的服务器运行Exchange 2010,并且我可以使用以下命令从A服务器对其运行Exchange 2010特定命令:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri $ConnectionURI -Credential $Credentials -Authentication Basic
Import-PSSession $Session

问题在于,我不能使用这个会话运行任何非 Exchange 命令,如果我尝试,它会说无法理解命令。我已经检查过使用 Invoke-Command 和 -Session 变量设置为我已建立的会话运行 Get-Command,只返回 Exchange 命令。
所以我想尝试使用 Invoke-Command、相关的 ComputerName、身份验证类型和凭据,但是这样做失败了。
Invoke-Command -ScriptBlock {Get-Service} -ComputerName "Servername.destination.com" -Credential $Credentials -Authentication "Basic"

以下是错误信息:

[servername.destination.com] Connecting to remote server failed with the following error message : The WinRM client can
not process the request. The authentication mechanism requested by the client is not supported by the server or unencry
pted traffic is disabled in the service configuration. Verify the unencrypted traffic setting in the service configurat
ion or specify one of the authentication mechanisms supported by the server.  To use Kerberos, specify the computer nam
e as the remote destination. Also verify that the client computer and the destination computer are joined to a domain.
To use Basic, specify the computer name as the remote destination, specify Basic authentication and provide user name a
nd password. Possible authentication mechanisms reported by server:     Negotiate Kerberos For more information, see th
e about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

所以我进入目标服务器的WSMAN配置,并设置相关选项,允许基本身份验证和未加密连接:

cd WSMan:\localhost\Service
Set-Item AllowUnencrypted $True
cd .\Auth
Set-Item Basic $True

我还把目标服务器加入了源域服务器的受信任主机列表中:

cd WSMan:\localhost\Client
Set-Item TrustedHosts servername.destination.com

这样做之后,错误信息发生了改变,但是并没有提供太多有用的信息:

PS WSMan:\localhost\Client> Invoke-Command -ScriptBlock {Get-Service} -ComputerName "servername.destination.com" -Creden
tial $Credentials -Authentication "Basic"
[servername.destination.com] Connecting to remote server failed with the following error message : Access is denied. Fo
r more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken

我还尝试使用域管理员凭据,通过-Credential(Get-Credential),但是这也遇到了相同的问题。

我尝试使用的用户是服务器上本地管理员用户组的成员,因此权限应该已经设置在PSSessionConfiguration容器上。

我希望能得到任何进一步的指针!我本来想使用WMI,但目前防火墙不支持它。


你可以尝试使用设置了PScredential的computerName参数进入PSsession,虽然它可能不会更好地工作,但也许会得到一个有帮助的不同错误。 - noam
昨天我尝试使用Enter-PSSession时也遇到了同样的错误。不知道是否有任何日志记录或其他可以检查更多细节的东西? - HungryHippos
就我个人而言,远程调用在从2003服务器到2008R2目标的不受信任域之间运行良好。 在目标上,运行enable-psRemoting,并且由于Y键一直提示相同的提示,所以不知何故必须单击A键以进行全部操作。 在源上,运行enter-psSession -comp target.domain.tld -credential (get-credential) ...并在提示时以domain\username格式输入凭据。 以防有帮助。 - noam
尽管听起来很奇怪,但在我完全删除了 -Authentication 开关之后,它运行得很好,它根本不喜欢基本身份验证,但让它自己做就适合我。 - HungryHippos
3个回答

28

1
在服务器端执行 Set-PSSessionConfiguration 还是客户端端执行,还是两者都执行? - Kiquenet
在目标机器上,为确保您连接的用户已获得授权。 - Olivier Boudry
更新链接:https://devblogs.microsoft.com/scripting/configure-remote-security-settings-for-windows-powershell/ - unbob
很奇怪,我使用全局管理员帐户时遇到了这个问题。 - user2924019

5

以管理员身份运行命令提示符或PowerShell ISE可以解决此问题。


1
当我运行Invoke-Command并引用本地主机时,这解决了我的问题。感到很有趣。谢谢! - James Ruskin
4
我通过将用户添加到远程管理用户组来解决这个问题。 - Der_Meister
1
Der_Meister 谢谢,它起作用了。也许只有内置的 Administrator 帐户可以通过默认安全策略设置绕过 UAC 障碍。其他 Administrators 帐户被强制获取 Restricted Token(具有 Users 而不是 Administrators)。他们的帐户只是普通的 Users,直到特权提升发生。因此,我们需要首先将其普通的 Users 帐户放入 Remote Management Users 组中。 - kenjiuno

0

在PS ISE中以管理员身份登录,这将解决PS远程问题。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接