使用invoke命令撤消管理员权限

时间:2019-06-19 00:37:43

标签: shell powershell scripting

我想使用invoke命令撤销管理员权限:

在我使用不带变量的命令的情况下,它可以正常工作的示例:

Invoke-Command -ComputerName TNLT725  -ScriptBlock { net localgroup "administrators" tchehidi /delete } -Credential tchehidi
The command completed successfully.

但是当我使用变量时,我会收到错误消息:

PS C:\Users\tchehidi\Desktop> $test = "tchehidi"
PS C:\Users\tchehidi\Desktop> Invoke-Command -ComputerName TNLT725  -ScriptBlock { net localgroup "administrators" $test
 /delete } -Credential tchehidi
[TNLT725] Connecting to remote server TNLT725 failed with the following error message : Access is denied. For more
information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (TNLT725:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken

0 个答案:

没有答案