Remove user from group using command line

by admin on April 17, 2009

We can delete users from a group using command line too. We can use below net localgroup command for this.

net localgroup grpup_name user_name /delete

For example to remove user John from administrators group we can run the below command.

net localgroup administrators John /delete

This command works on all editions of Windows OS i.e Windows 2000, Windows XP, Windows Server 2000, Windows Vista and Windows 7. In Vista and Windows 7, even if you run the above command from administrator login you may still get access denied error like below.

C:\> net localgroup administrators techblogger /delete
System error 5 has occurred.
Access is denied.

The solution for this is to run the command from elevated administrator account. See how to open elevated administrator command prompt

When you run the above command from elevated command prompt:

C:\Windows\system32>net localgroup administrators techblogger /delete

The command completed successfully.

Below are few more examples for net localgroup command.

To delete a user from Remote desktop users group:

net localgroup "Remote desktop users" username /delete

To remove a user from Power users group:

net localgroup "Power users" username /delete

To remove a user from Debugger users group:

net localgroup "Debugger users" username /delete

How to remove all users from a group?

There is no single direct command to delete all users from a group. You can use net localgroup in combination with for command to do this. I am giving a script below which seems to be working.

for /F %i in ('net localgroup group_name') do net localgroup group_name %i /delete

Just replace the group_name with your group name. Note that this runs a series of /delete operations and in the first few cases it returns errors. (If you understand the above command, you will be knowing the reason for this.)

There could be a better solution to do this..but this is the one I know of..

Related Posts:
Get list of user groups
Create a user group

{ 4 comments… read them below or add one }

Anonymous September 6, 2010 at 4:53 am

How to remove all users from a group using a single command?

Reply

Ricardo November 4, 2010 at 12:39 am

Having a bit of a problem here. I used the Offline NT registry editor at http://pogostick.net/~pnh/ntpasswd/ to elevate a normal user account to admin, and now I cannot change it from admin to normal user.
I inputted the following cmds in command line:
net localgroup administrators CompAdmin /delete
And I got sys error 1377 that says CompAdmin is not a member of the group. Then I input net localgroup administrators CompAdmin /add and it says the account is already a member of the group..what can I do? I cannot reinstall my OS or recreate another account..

Reply

Techblogger November 4, 2010 at 4:47 am

Ricardo,

May be the registry hack is not a complete solution to elevate a user to administrator.. It's always better to be cautious about registry hacks..Though most of the operations involve single registry changes some operations require changing multiple keys in the registry..

Have you tried it from GUI? I mean using nusrmgr.cpl or compmgmt.msc

One solution I would suggest is to undo the registry change the tool has done..This can work only if you have the details of what the tool has done..

Other suggestion is to delete that user and add a new user account afresh.. take back up of all the user data..

Reply

Erik August 1, 2013 at 8:38 pm

Thanks, I used PSExec to run this against remote computer and saved HOURS of work.

psexec \\ c:\windows\system32\net localgroup administrators  /delete

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: