我可以在遠程機器上成功使用NET USE
和NET 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.
您是否嘗試過使用net命令(通過/ user:Domain \ username)傳遞用戶名? –
@PeterSchneider - 是的,它會產生不同的錯誤輸出。 – lit
您是否看到[this](https://stackoverflow.com/questions/21147784/net-localgroup-administrators-equivalent-in-powershell)...? –