2017-04-03 305 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。 –