Windows 2008 – Remove Windows User Remotely [closed]

On a Windows 2008 server, how to remove an user from Admin group. Below command works on local machine, say A

net localgroup administrators "Domain\username" /delete 

what i require is a windows command, to do the same on another server B, from Server A,instead of logging into each server manually and running command.

I am not windows admin, so dont have access to win admin tools.

Answer

With PowerShell 2.0 and newer, you can use Invoke-Command against a remote computer:

$cmd = {.\cmd.exe /c net use localgroup Administrators "Domain\username" delete}
Invoke-Command -ComputerName serverB -ScriptBlock $cmd

Alternatively, you can download PsExec and use it to run the command on serverB:

psexec \\serverB -u adminUser net localgroup Administrators "Domain\username" /delete

adminUser should be a member of the Administrators group on serverB
You’ll be prompted for the password when you hit enter. You can specify -p P@$$w0rd! if you need it for scripting.

Attribution
Source : Link , Question Author : victor , Answer Author : Mathias R. Jessen

Leave a Comment