≡ Menu

Remove user from group using command line

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:\>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

14 comments… add one
  • Anonymous

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

  • Ricardo

    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..

  • Techblogger

    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..

  • Erik

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

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

    How to delete the logged in user from a group? I can’t specify a specific user name in the command, I just want to use the logged in user name.

  • tk

    Hi,
    was hoping you help me out. Im trying to delete a security group from the local administrators group. using the following syntax
    net localgroup Administrators TDBFG\Test Group /delete

    but I get the messaged that “there is no such global user or group : test” and “there is no such global user or group “group”.

    I think its because of the space. can you please advise? thanks.

    • admin

      Yes, it’s because of the space. You should enclose the group name into double quotes.

      net localgroup Administrators "TDBFG\Test Group" /delete
  • Midhun

    Can I delete the one particular user from N number of servers using above ?Is there any chance for that

    • Srini

      You can use psexec tool to run net user commands on each of the servers. Curious to know – do you have this user as a local user on N servers? or is it a domain user account and was added to multiple servers?

  • Suresh

    I am trying to delete all users from a Administrator group in Single Command. So i tried this command : for /F %i in (‘net localgroup group_name’) do net localgroup group_name %i /delete

    When i run this, it is worked for all accounts “except” one user where the account name has space for example : “Suresh Gopalan” I know we have to give double quotes for this to work, but here i do not know where to give in the above command. Could any one help?

  • Buddie

    i have a domain user account added to multiple servers; i have tried removing but get the error code 1, what could be the solution?
    Thank you,

  • Chris

    These people sound like they are trying to hack people like my computer has been hacked. I put in your commands and many many more but keep getting the system error 5 response. I’m right in front of the computer. Someone is slowly but surely putting administration restrictions on all my programs to where I can’t access any of them. They crashed my other computer now this one’s almost dead also. What can I do to stop this,? I would appreciate any advice. Im at my ropes end here. Computer just now crashed with command net user administrator remove and it’s been black since. I’m loosing my mind and that’s saying a lot as I’m schitzophrenic already. Please give me some help so I can at least fight back.

  • sumit

    Hi,

    I want to delete multiple users not all from local group.

    Need a help

    Thanks
    Sumit

  • Hernan

    please how to create this command as patch file i tried to do this as .bat file and there is no action taken

Cancel reply

Leave a Comment