In today’s digital age, managing users and groups efficiently is essential for smooth computer operations. Windows 11, Microsoft’s latest OS, offers robust tools for this purpose. One of these is PowerShell, which allows for streamlined user and group management. Below, we dive deep into managing local users and groups using PowerShell in Windows 11.
1. Get Local Users List Using PowerShell
To retrieve a list of local users:
Get-LocalUser
2. Getting User List, Local and Non-local
For a comprehensive list that includes both local and non-local users, combine local user data with Active Directory information:
<code>Get-LocalUser Get-ADUser -Filter *</code>
(Note: The latter command requires the Active Directory module.)
3. Add and Remove User Using PowerShell
- Adding a User:
<code>New-LocalUser -Name "Username" -Description "Description of the User" -NoPassword</code>
- Removing a User:
<code>Remove-LocalUser -Name "Username"</code>
4. Manage Groups Using PowerShell
- View all local groups:
<code>Get-LocalGroup</code>
- Create a new group:
New-LocalGroup -Name "GroupName" -Description "Description of the Group"
- Remove a group:
<code>Remove-LocalGroup -Name "GroupName"</code>
5. Manage Group Members Using PowerShell
- Add a member to a group:
<code>Add-LocalGroupMember -Group "GroupName" -Member "Username"</code>
- Remove a member from a group:
<code>Remove-LocalGroupMember -Group "GroupName" -Member "Username"</code>
- View members of a group:
<code>Get-LocalGroupMember -Group "GroupName"</code>