Powershell New-PSSession访问被拒绝 - 管理员帐户

问题描述 投票:3回答:3

我尝试使用PowerShell PSSession cmdlet,但我正在努力解决Access Denied Error问题。

我尝试做的是使用管理员帐户IN运行命令qazxsw poi(或qazxsw poi),不幸的是我收到了拒绝访问错误。

我正确地遵循所有说明,因为在另一台服务器上我可以毫无困难地运行这些命令。

另外我想告诉New-PSSession回复我的回复。我正在使用内置管理员帐户并且已经检查过Enter-PSSession所有权限似乎都可以。我没有更多的想法,寻求帮助。

UPDATE

我发现了一个有趣的行为:

我们假设:

  • 机器的IP地址是22.222.222.222
  • 我使用管理员凭据通过远程桌面登录

我使用以下命令:

test-wsman

我可以在其他服务器上添加它,当我运行完全相同的命令时,所有命令都成功。

有任何想法吗?

powershell windows-server-2012-r2 winrm
3个回答
1
投票

PS会话用于访问远程系统。为此你必须做一些配置:

1)确保winrm服务在所有目标系统以及本地系统中运行。

2)您必须启用PS Remoting。 Enable-PSRemoting将计算机配置为接收与WS-Man一起发送的PowerShell远程命令。

因此,以管理员身份启动Windows PowerShell

Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI

3)您需要将远程计算机添加到WinRM中本地计算机的可信主机列表中。为此,请键入:

new-pssession // access denied

new-pssession localhost // access denied

new-pssession 127.0.0.1 // access denied

new-pssession 22.222.222.222 // Session created ! It's working !

new-pssession 22.222.222.222 -Credential Get-Credential // access denied (using the same administrator credentials which I'm using for RDP)

4)使用以下方法检查配置:

Enable-PSRemoting –Force

完成后,您可以使用New-Pssession命令创建与目标系统的交互式会话。

否则,您可以使用Invoke-Command执行一些远程操作,如下所示:

我在评论部分提到它是如何工作的。样品:

winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'

既然你已经更新了这个问题:让我明白一点:

127.0.0.1和localhost - 都指向本地系统。表示您必须将它们添加到本地系统的可信主机列表中。不建议将PSSession用于本地系统,因为您可以直接在PS控制台中运行所有ps cmdlet。

22.222.222.222 - 工作原因您已将其添加到可信主机列表中,并且默认情况下使用Windows身份验证

22.222.222.222 -Credential Get-Credential ----因为格式有点不对而无法正常工作。使用这样:

winrm quickconfig

希望它能帮到你。


1
投票

我遇到了这个问题,发现我传入的用户名需要是FQDN。即[email protected]而不仅仅是用户名。一旦我更新到它的工作。


0
投票

试试这个:$username = "Username" $password = "Password" $secstr = New-Object -TypeName System.Security.SecureString $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)} $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr # will list all the processess in the remote system # if you are the entireprise admin or the domain admin then you do not have to pass the credentials. It will take the windows authentication by default. Invoke-Command -ComputerName RemoteServer -ScriptBlock {Get-Process } -Credential $cred

它调用一个会话,然后使用您提供的凭据注册PSSessionConfiguration。基本上为DoubleHop提供凭据

© www.soinside.com 2019 - 2024. All rights reserved.