2017-05-30 58 views
0

我可以在遠程機器上成功使用NET USENET USER命令。爲什麼不是NET LOCALGROUP爲什麼Invoke-Command {net localgroup}失敗?

PS C:\src\powershell> Invoke-Command -ComputerName OTHERMACHINE -ScriptBlock { & NET LOCALGROUP } 
System error 1312 has occurred. 
    + CategoryInfo   : NotSpecified: (System error 1312 has occurred.:String) [], Rem 
    oteException 
    + FullyQualifiedErrorId : NativeCommandError 
    + PSComputerName  : OTHERMACHINE 

A specified logon session does not exist. It may already have been terminated. 

傳遞/ USER參數會產生不同的錯誤。

PS C:\src\powershell> Invoke-Command -ComputerName OTHERMACHINE -ScriptBlock { & net localgroup /USER:THEDOM\theuser } 
The option /USER:THEDOM\theuser is unknown. 
    + CategoryInfo   : NotSpecified: (The option /USE...son is unknown.:String) [], R 
    emoteException 
    + FullyQualifiedErrorId : NativeCommandError 
    + PSComputerName  : OTHERMACHINE 

The syntax of this command is: 
NET LOCALGROUP 
[groupname [/COMMENT:"text"]] [/DOMAIN] 
       groupname {/ADD [/COMMENT:"text"] | /DELETE} [/DOMAIN] 
       groupname name [...] {/ADD | /DELETE} [/DOMAIN] 
More help is available by typing NET HELPMSG 3506. 
+0

您是否嘗試過使用net命令(通過/ user:Domain \ username)傳遞用戶名? –

+0

@PeterSchneider - 是的,它會產生不同的錯誤輸出。 – lit

+0

您是否看到[this](https://stackoverflow.com/questions/21147784/net-localgroup-administrators-equivalent-in-powershell)...? –

回答

0

我相信這是雙跳問題。如果您嘗試在使用Enter-PSSession創建的會話中執行net localgroup administrators,則會出現相同的錯誤:「發生系統錯誤1312」。和「指定的登錄會話不存在,它可能已被終止。」

net.exe正在嘗試重新進行身份驗證,但無法重新使用會話的憑據。您可能成功使用CredSSP,這需要一些設置,並且IIRC可能會產生安全隱患。你必須要enable CredSSP on the remote system and local system, and then delegate correctly。即使如此,我仍然看到有關這項工作的報道有衝突。甚至可能有security policies阻止它。我個人不會用net.exe。對於那些基本的東西來說,這是太多的箍環。你可以retrieve the members of a local group remotely via the ADSI provider,這可能更容易,更有可能工作。

+0

是的,我曾嘗試過'Enter-PSSession',並得到相同的結果。 「NET」命令工作而哪些不工作似乎很奇怪。無論如何,使用[ADSI]會更多PoSH。由於似乎沒有更好的解釋,我會以此作爲答案。 – lit