Home » PowerShell » How to Get Local User Accounts using PowerShell

How to Get Local User Accounts using PowerShell

Use the `Get-LocalUser` command in PowerShell to get local user accounts. This command gets the default built-in user account, local user accounts that you have created, and local accounts that you connected to Microsoft accounts.

Here is the PowerShell script to get local user accounts.

Get-LocalUser

In this article, we will discuss how to get all local user accounts, get a local user account by using its name, get a user account that has specified SID.

How to Get Local User Accounts Using PowerShell

The command to get local user accounts using PowerShell is Get-LocalUser. This command gets all the local user accounts and built-in user accounts.

Get-LocalUser

The output of the above PowerShell script returns a list of all local user accounts on the computer.

PS C:\> Get-LocalUser

Name           Enabled Description
----           ------- -----------
admin       True    Built-in account for administering the computer/domain
Guest          False   Built-in account for guest access to the computer/domain
krbtgt         False   Key Distribution Center Service Account
toms           True
ErickJ         True
garyw          True
chrisd         True
adam           True
nathan         False
Don            True

How to Get a Local User Account by Using its Name in PowerShell

Use the Get-LocalUser command with the Name parameter to specify the user name to get a local user account.

Get-LocalUser -Name Arons

In the above PowerShell script, the Get-LocalUser command uses the Name parameter to specify the local user account name and get his account that includes Name, Enabled, and Description.

The output of the above PowerShell script to get a local user account is given below.

Get Local User Account
Get a Local User Account

How to Get a Local User Account that has Specific SID

Use the Get-LocalUser cmdlet to get a local user account, it uses the SID property to specify the user SID and returns the local user account.

Get-LocalUser -SID S-1-5-21-1326752099-4012446882-462961959-2601

The output of the above PowerShell script gets a local user account that has the specified SID.

PS C:\> Get-LocalUser -SID S-1-5-21-1326752099-4012446882-462961959-2601

Name  Enabled Description
----  ------- -----------
garyw True

Conclusion

I hope the above article on how to get the local user account using the PowerShell Get-LocalUser command is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

Microsoft.PowerShell.LocalAccounts Module

Add-LocalGroupMember

Get-LocalGroupMember

New-LocalUser

Enable-LocalUser

Disable-LocalUser

Rename-LocalUser

Set-LocalUser