- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add users and groups to the local groups on Windows System using PowerShell?
To add users to the local groups using PowerShell, we need to use the Add-LocalGroupMember command (Module − Microsoft.PowerShell.LocalAccounts).
Add-LocalGroupMember -Group "Administrators" -Member "NewLocalUser","labdomain\Alpha","Labdomain\ITSecurity"
The above command adds 2 users (NewLocalUser (Local) and Alpha (Domain)) and one Domain Security Group ITSecurity to the Local Administrators group.
You can also use the other local group name instead of Administrators.
To add the new users in the local group on the remote system(s) use the Invoke-Command method. For example,
Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16{ Add-LocalGroupMember -Group "Administrators" -Member "NewLocalUser","labdomain\Alpha","Labdomain\ITSecurity" }
Please note − To run the above command, the remote server must use the PS version 5.1 or advance version.
You can also use the command prompt if you don’t have the PS version 5.1 or higher to add users to the group using the below command syntax.
net localgroup groupname username /add
For example,
net localgroup Administrators "labdomain\alpha" /add
In the above example, we are adding LabDomain user Alpha to the local Administrators group. You can replace the Administrators with the other group name. For the local user/group, we just need to provide the username or group name without specifying the domain. For example,
net localgroup Administrators "NewLocalUser" /add
To add the above commands remotely,
Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{ Net Localgroup Administrators "LabDomain\Alpha" /add }