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..
Get list of user groups
Create a user group