2017-05-30 55 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