我尝试使用powershell PSSession cmdlet,但我正在与访问拒绝错误进行斗争。
我试图使用管理员帐户运行命令New-PSSession
(或Enter-PSSession
),不幸的是,我收到了拒绝访问的错误。
我相信,我正确地遵循了所有的指令,因为在另一台服务器上,我可以毫无问题地运行这些命令。
此外,我想通知您,test-wsman
会给我一个回复。我正在使用内置管理员帐户,并且已经检查了Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI
,所有特权似乎都是正常的。我没有更多的想法,寻求帮助。
更新
我发现一个有趣的行为:
让我们假设:
我使用以下命令:
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)
我可以在另一台服务器上添加,当我运行完全相同的命令时,所有命令都是成功的。
有什么想法吗?
发布于 2017-04-03 17:45:18
PS会话用于访问远程系统。为此,您必须执行很少的配置:
1)确保winrm服务在所有目标系统以及本地系统中运行。
2)您必须启用PS远程处理。启用-PSRemoting配置计算机以接收与WS一起发送的PowerShell远程命令.
因此,以管理员身份启动Windows PowerShell
Enable-PSRemoting –Force
3)您需要将远程计算机添加到WinRM中本地计算机的受信任主机列表中。为此,请键入:
winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'
4)使用以下方法检查配置:
winrm quickconfig
完成之后,您可以使用New-Pssession命令创建与目标系统的交互式会话。
否则,您可以使用Invoke-Command执行一些远程操作,如下所示:
我在评论部分提到了它是如何工作的。样本:
$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和localhost -都指向本地系统。意味着您必须将它们添加到本地系统的受信任主机列表中。对于本地系统使用PSSession是不可取的,因为您可以直接运行ps控制台中的所有PS。
22.222.222.222 --因为在受信任的主机列表中添加了它,默认情况下它使用的是windows身份验证。
22.222.222.222 -Credential Get-凭证--由于格式有点错误,无法工作。像这样使用:
New-PSSession -ComputerName 22.222.222.222 -Credential (Get-Credential)
希望它能帮到你。
https://stackoverflow.com/questions/43190429
复制相似问题