
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 }
- Related Questions & Answers
- How to get the list of local groups using PowerShell?
- How to delete the local group from the windows system using PowerShell?
- How to block ports on the Windows Operating System using PowerShell?
- How to enable or disable local user on Windows OS using PowerShell?
- How to get the Application security groups of the Azure VM using PowerShell?
- How to add the user to the local Administrators group using PowerShell?
- How to create a new local user in windows using PowerShell?
- How to Install the Azure CLI on Windows using PowerShell?
- How to add the entry in the windows host file using PowerShell?
- How to open a port in the Windows Operating System using PowerShell?
- How to get connected remote desktop users on computers using PowerShell?
- How to enable credssp authentication on windows server using PowerShell?
- Three-Phase Transformer Vector Groups – How are the Vector Groups Divided?
- How to delete the windows certificate using PowerShell?
- How to get all the user profiles on the System using PowerShell?