Table of Contents
The user must have administrative privileges to use the following commands. Also, the user must be created on the computer to add to the
administratorsgroup.
Using *-LocalGroupMember Cmdlet
Using PowerShell, we can use the *-LocalGroupMember command to add/check/remove one or multiple users to the administrators group. Here, * can be Add, Get, or Remove based on what we want to achieve. Let’s learn each of them below.
Use the Add-LocalGroupMember command to add a user to the administrators group using PowerShell.
|
1 2 3 |
Add-LocalGroupMember -Group "Administrators" -Member "Tony" |
The above command will not show any output or error if everything is in the right place.
Use the Get-LocalGroupMember command to check a user is added to the administrators group using PowerShell.
|
1 2 3 |
Get-LocalGroupMember -Group "Administrators" |
|
1 2 3 4 5 6 7 |
ObjectClass Name PrincipalSource ----------- ---- --------------- User DESKTOP-KMF\Administrator Local User DESKTOP-KMF\Mary Local User DESKTOP-KMF\Tony Local |
Use the Remove-LocalGroupMember command to remove a user from the administrators group using PowerShell.
|
1 2 3 |
Remove-LocalGroupMember -Group "Administrators" -Member "Tony" |
This command will not display any output or message but will generate an error if you have done something incorrectly.
Use the Add-LocalGroupMember command to add multiple users to the administrators group using PowerShell.
|
1 2 3 |
Add-LocalGroupMember -Group "Administrators" -Member "Tony", "Adam" |
If everything is correct, the above command will not show any output, warning or error.
Use the Get-LocalGroupMember command to check if multiple users are added to the administrators group using PowerShell.
|
1 2 3 |
Get-LocalGroupMember -Group "Administrators" |
|
1 2 3 4 5 6 7 8 |
ObjectClass Name PrincipalSource ----------- ---- --------------- User DESKTOP-KMF\Administrator Local User DESKTOP-KMF\Adam Local User DESKTOP-KMF\Mary Local User DESKTOP-KMF\Tony Local |
Use the Remove-LocalGroupMember command to remove multiple users from the administrators group using PowerShell.
|
1 2 3 |
Remove-LocalGroupMember -Group "Administrators" -Member "Tony", "Adam" |
This command will not show any output or message but will display an error if you have done something wrong.
In the above examples, the commands are composed of different options whose brief description is given below:
Add-LocalGroupMembercmdlet was used to add one or multiple users to the local group on Windows PC.Get-LocalGroupMembercmdlet was used to retrieve one or multiple users from the local group on Windows PC.Remove-LocalGroupMemberwas used to remove one or more users from the local group on a Windows computer.-Groupparameter was used to mention the local group’s name. In the above examples, the group name is"Administrators".-Memberparameter was used to specify the user’s name that will be added to or removed from the local group."Administrators"is the name of the local group."Tony"&"Adam"are the placeholders for theusernamevariable.
Using net localgroup Command
Using PowerShell, we can use the net localgroup command to add/check/remove one or multiple users to the administrators group. Let’s learn each of them below.
Use the net localgroup command to add a user to the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators /add Tony |
|
1 2 3 |
The command completed successfully. |
Use the net localgroup command to check if a user is added to the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators |
|
1 2 3 4 5 6 7 8 9 10 |
Alias name administrators Comment Administrators have complete and unrestricted access to the computer/domain Members ------------------------------------------------------------------------------- Administrator Mary Tony The command completed successfully. |
Use the net localgroup command to remove a user from the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators Tony /delete |
Use the net localgroup command to add multiple users to the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators /add Tony, Adam |
|
1 2 3 |
The command completed successfully. |
Use the net localgroup command to check if multiple users are added to the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators |
|
1 2 3 4 5 6 7 8 9 10 11 |
Alias name administrators Comment Administrators have complete and unrestricted access to the computer/domain Members ------------------------------------------------------------------------------- Administrator Adam Mary Tony The command completed successfully. |
Use the net localgroup command to remove multiple users from the administrators group using PowerShell.
|
1 2 3 |
net localgroup administrators Tony, Adam /delete |
|
1 2 3 |
The command completed successfully. |
In the above examples, the commands are comprised of different options whose brief description is given below.
netis the command utility we use for different network-related tasks in Windows operating systems.localgroupis the sub-command we used to manage local groups on the Windows PC.administratorsis the local group’s name, which we targeted in the above commands. It is the built-inadministratorsgroup in Windows PC./addoption was specified to add the given user(s)./deleteoption was used to delete the given user(s).Tony&Adamare the values for theusernameplaceholder to be added/removed from theadministratorsgroup. The usernames will be separated by a comma if there are two or more usernames.
Use the
net localgroup administrators | findstr /c:"Tony"command if you are interested in getting that one username only for which you want to check if it is added to theadministratorsgroup or not. You will get the specified username if it is added; otherwise, not. Don’t forget to replace"Tony"with your username.
That’s all about PowerShell add user to administrators group.