2017-04-03 311 views
2

我尝试使用powershell PSSession cmdlet,但我正在努力与访问拒绝错误。Powershell新的PSSession访问被拒绝 - 管理员帐户

我试图做的是使用管理员帐户我运行命令New-PSSession(或Enter-PSSession),不幸的是我收到访问拒绝错误。

我遵循所有正确的说明,我相信,导致在其他服务器上我可以毫不费力地运行这些命令。

另外我想通知test-wsman给我回复。我正在使用内置管理员帐户并已检查Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI 所有权限似乎都没问题。我没有更多的想法,寻求帮助。

UPDATE

我发现一个有趣的现象:

让我们假设:

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

我用下面的命令:

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) 

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

任何想法?

回答

0

PS会话用于访问远程系统。为此,您必须执行几项配置:

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

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

因此,启动Windows PowerShell作为管理员

Enable-PSRemoting –Force 

3)您需要在远程计算机添加到受信任主机列表中WinRM的本地计算机。要做到这一点,类型:

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

4)检查使用配置:

winrm quickconfig 

完成后,您可以使用新的PSSession命令创建一个交互式会话目的地系统。

否则,您可以使用调用命令像下面执行一些远程操作:

我在评论区它是如何工作的提及。 样品:

$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 

既然你已经更新了一个问题:让我告诉你一点忠告:

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

22.222.222.222 - 和工作,因为你有加,在可信主机列表它默认

22.222.222.222使用Windows身份验证-Credential GET-凭据 - ---不工作,因为格式有点不对。像这样使用:

New-PSSession -ComputerName 22.222.222.222 -Credential (Get-Credential) 

希望它可以帮助你。

+0

感谢您的回答,但正如我前面提到的,我做了所有这4点,我得到了访问被拒绝的错误。 –

+0

请在这种情况下发布错误截图。让我们看看我们是否能从中得到一些东西。 –

+0

Ranadip Dutta - 请检查我的更新。任何想法可能是错误的。有这些问题的机器是VPS。 –