Windows PowerShell can also be used to manage Local Users and Groups. This affirms the principle of Windows 11/10 being a multiuser operating system. There are other GUI-based utilities to manage Local Users and Groups. However, some System administrators might like to use the command-line utility to manage these users and groups. That is what we are going to learn more about in this guide.
How to Add or Delete Local Users and Groups using PowerShell
We will now be covering this guide in two parts. They are the following:
- Managing Local Users.
- Managing the User Groups.
To begin, you will need to open Windows PowerShell as an Administrator.
1] Managing Local Users
This cmdlet will help you to find all the details about all the local user accounts. These details will include the Account Name, Enabled status, and the description. The cmdlet is:
Get-LocalUser
You can also get customized data about various objects related to your account. For example, we had used an object to check when was the Local account’s password was set last time. The cmdlet we used was:
Get-LocalUser -Name root | Select-Object PasswordLastSet
The skeleton for this cmdlet is:
Get-LocalUser -Name root | Select-Object *
And you can use objects like the following to get different sorts of information curated just for you:
-
AccountExpires
-
Description
-
Enabled : True
-
FullName
-
PasswordChangeableDate
-
PasswordExpires
-
UserMayChangePassword
-
PasswordRequired
-
PasswordLastSet
-
LastLogon
-
Name
-
SID
-
PrincipalSource
-
ObjectClass
2] Managing the User Groups
This cmdlet will help you to find all the details about all the groups of the local user accounts:
Get-LocalGroup
If you wish to create a new Local User Group, use this cmdlet:
New-LocalGroup -Name <NAME OF THE GROUP> -Description '<ENTER THE DESCRIPTION OF THE GROUP HERE>'
Now, in order to add Local User Accounts to a particular group, you can use this cmdlet:
Add-LocalGroupMember -Group '<NAME OF THE GROUP' -Member ('NAME 1','NAME 2','<ROLE>') -Verbose
Alternatively, this cmdlet can be used for the same reasons, too:
Get-Localuser -Name john | Add-LocalGroupMember -Group '<NAME OF THE GROUP>'
To display all the User Accounts that are a part of a particular group, use this command:
Get-LocalGroupMember -Group ''
Lastly, if you wish to remove a local user account from a group, use this cmdlet:
Remove-LocalGroupMember -Group '<NAME OF THE GROUP>' –Member <NAME OF THE LOCAL USER ACCOUNT>
These are some basic managing cmdlets for a user to manage Local Users and Groups using Windows PowerShell.
Also read: How to Manage Local User and Group Management in Windows Home using Command line.
I hope you found this guide useful.