Development

How to List Local Users and Groups In PowerShell

Captain Salem 5 min read

How to List Local Users and Groups In PowerShell

Windows users and groups are a way to manage access to resources on a computer. Users can be added to groups, and the permissions for the group can be set to allow or deny access to specific resources, such as files, folders, and system settings.

There are several built-in groups in Windows, such as the Administrators group, which has full control over the computer, and the Users group, which has limited access. You can also create custom groups and add users to them.

However, as a sys administrator, you will often be working in the terminal session, and managing users and groups from the terminal can be hugely beneficial.

In this post, you will learn how to list users and groups in Windows using Windows PowerShell.

List Windows Users in PowerShell using Get-LocalUser Cmdlet.

The Get-LocalUser cmdlet is a PowerShell cmdlet that retrieves the local user accounts on a computer. It returns a list of Microsoft.Management.Infrastructure.CimInstance objects that represent the local user accounts.

By default, the cmdlet returns all local user accounts on the computer. Example:

Get-LocalUser

This should return details of the available user accounts as:

Name               Enabled Description
----               ------- -----------
admin              True
Administrator      False   Built-in account for administering the computer/domain
DefaultAccount     False   A user account managed by the system.
Guest              False   Built-in account for guest access to the computer/domain
WDAGUtilityAccount False   A user account managed and used by the system for Windows....

You can also use the -Name parameter to specify a specific user account by name. For example, to get the local user account with the name “admin”, you can use the following command:

Get-LocalUser -Name "admin"

Output:

Name  Enabled Description
----  ------- -----------
admin True

The Get-LocalUser cmdlet has several other parameters that allow you to control the properties that are returned for each user account, such as FullName, Description, and PasswordLastSet. You can use these parameters to customize the output of the cmdlet.

For example, to list the names only of all local user accounts, you can use the following command:

Get-LocalUser | Select-Object Name

Output:

Name
----
admin
Administrator
DefaultAccount
Guest
WDAGUtilityAccount

List Users in PowerShell Using net Command

You can also use the net command to list users and groups. To list all users, you can use the following command:

net user

Output:

User accounts for \\SERVER

-------------------------------------------------------------------------------
admin                    Administrator            DefaultAccount
Guest                    WDAGUtilityAccount
The command completed successfully.

List Users in PowerShell Using Get-WmiObject Cmdlet

You can also use the Get-WmiObject cmdlet to list users and groups. To list all users, you can use the following command:

Get-WmiObject -Class Win32_UserAccount

Output:

AccountType : 512
Caption     : SERVER\admin
Domain      : SERVER
SID         : S-1-5-21-697903660-3891131852-320673488-1001
FullName    :
Name        : admin

AccountType : 512
Caption     : SERVER\Administrator
Domain      : SERVER
SID         : S-1-5-21-697903660-3891131852-320673488-500
FullName    :
Name        : Administrator

AccountType : 512
Caption     : SERVER\DefaultAccount
Domain      : SERVER
SID         : S-1-5-21-697903660-3891131852-320673488-503
FullName    :
Name        : DefaultAccount

AccountType : 512
Caption     : SERVER\Guest
Domain      : SERVER
SID         : S-1-5-21-697903660-3891131852-320673488-501
FullName    :
Name        : Guest

AccountType : 512
Caption     : SERVER\WDAGUtilityAccount
Domain      : SERVER
SID         : S-1-5-21-697903660-3891131852-320673488-504
FullName    :
Name        : WDAGUtilityAccount

List Groups in PowerShell using Get-LocalGroup Cmdlet

The Get-LocalGroup cmdlet is a PowerShell cmdlet retrieves the local groups on a computer. It returns a list of Microsoft.Management.Infrastructure.CimInstance objects that represent the local groups.

Example:

Get-LocalGroup

Output:

Name                                Description
----                                -----------
docker-users                        Users of Docker Desktop
Access Control Assistance Operators Members of this group can remotely query authorization..
Administrators                      Administrators have complete and unrestricted access...
Backup Operators                    Backup Operators can override security restrictions for..
Cryptographic Operators             Members are authorized to perform cryptographic...
Device Owners                       Members of this group can change system-wide settings.
Distributed COM Users               Members are allowed to launch, activate and use...
Event Log Readers                   Members of this group can read event logs from local...
Guests                              Guests have the same access as members of the Users group
Hyper-V Administrators              Members of this group have complete and unrestricted...
IIS_IUSRS                           Built-in group used by Internet Information Services.
Network Configuration Operators     Members in this group can have some administrative...
Performance Log Users               Members of this group may schedule logging of performance
Performance Monitor Users           Members of this group can access performance counter data
Power Users                         Power Users are included for backwards compatibility and.
Remote Desktop Users                Members in this group are granted the right to logon...
Remote Management Users             Members of this group can access WMI resources over...
Replicator                          Supports file replication in a domain
System Managed Accounts Group       Members of this group are managed by the system.
Users                               Users are prevented from making accidental or...

You can also use the -Name parameter to specify a specific group by name. For example, to get the local group with the name “Administrators”, you can use the following command:

Get-LocalGroup -Name "Power Users"

Output:

Name        Description
----        -----------
Power Users Power Users are included for backwards compatibility and possess limited administrative powers

The Get-LocalGroup cmdlet has several other parameters that allow you to control the properties that are returned for each group, such as Description, GroupType, and SID. You can use these parameters to customize the output of the cmdlet.

For example, to list the names of all local groups, you can use the following command:

Get-LocalGroup | Select-Object Name

Output:

Name
----
docker-users
Access Control Assistance Operators
Administrators
Backup Operators
Cryptographic Operators
Device Owners
Distributed COM Users
Event Log Readers
Guests
Hyper-V Administrators
IIS_IUSRS
Network Configuration Operators
Performance Log Users
Performance Monitor Users
Power Users
Remote Desktop Users
Remote Management Users
Replicator
System Managed Accounts Group
Users

List Groups in PowerShell Using Get-WmiObject Cmdlet

We can also list local groups using the Get-WmiObject cmdlet as shown:

Get-WmiObject -Class Win32_Group

Output:

Caption                                    Domain Name                                SID
-------                                    ------ ----                                ---
SERVER\Access Control Assistance Operators SERVER Access Control Assistance Operators S-1-5-32-579
SERVER\Administrators                      SERVER Administrators                      S-1-5-32-544
SERVER\Backup Operators                    SERVER Backup Operators                    S-1-5-32-551
SERVER\Cryptographic Operators             SERVER Cryptographic Operators             S-1-5-32-569
SERVER\Device Owners                       SERVER Device Owners                       S-1-5-32-583
SERVER\Distributed COM Users               SERVER Distributed COM Users               S-1-5-32-562
SERVER\Event Log Readers                   SERVER Event Log Readers                   S-1-5-32-573
SERVER\Guests                              SERVER Guests                              S-1-5-32-546
SERVER\Hyper-V Administrators              SERVER Hyper-V Administrators              S-1-5-32-578
SERVER\IIS_IUSRS                           SERVER IIS_IUSRS                           S-1-5-32-568
SERVER\Network Configuration Operators     SERVER Network Configuration Operators     S-1-5-32-556
SERVER\Performance Log Users               SERVER Performance Log Users               S-1-5-32-559
SERVER\Performance Monitor Users           SERVER Performance Monitor Users           S-1-5-32-558
SERVER\Power Users                         SERVER Power Users                         S-1-5-32-547
SERVER\Remote Desktop Users                SERVER Remote Desktop Users                S-1-5-32-555
SERVER\Remote Management Users             SERVER Remote Management Users             S-1-5-32-580
SERVER\Replicator                          SERVER Replicator                          S-1-5-32-552
SERVER\System Managed Accounts Group       SERVER System Managed Accounts Group       S-1-5-32-581
SERVER\Users                               SERVER Users                               S-1-5-32-545
SERVER\docker-users                        SERVER docker-users                        S-1-5-21-697903660-3891131852-320673488-1002

List Local Groups in PowerShell Using net Command

We can also list local groups using the net command as shown:

net localgroup

Output:


Aliases for \\SERVER

-------------------------------------------------------------------------------
*Access Control Assistance Operators
*Administrators
*Backup Operators
*Cryptographic Operators
*Device Owners
*Distributed COM Users
*docker-users
*Event Log Readers
*Guests
*Hyper-V Administrators
*IIS_IUSRS
*Network Configuration Operators
*Performance Log Users
*Performance Monitor Users
*Power Users
*Remote Desktop Users
*Remote Management Users
*Replicator
*System Managed Accounts Group
*Users
The command completed successfully.

Conclusion

In this tutorial, you discovered various methods to get a list of all local users and groups on a Windows system using PowerShell.

We hope you enjoyed this tutorial; leave us a comment below and share!!

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.