Home » PowerShell Tips » PowerShell – Get User SID in Active Directory

PowerShell – Get User SID in Active Directory

SID (Security IDentifier) is a unique id number assigned to each user on windows computer, group or computer on domain-controlled network. You can get current user SID in Active Directory using PowerShell Get-LocalUser cmdlet or ad user SID using Get-ADUser cmdlet in PowerShell.

In this article, I will explain how to find SID in active directory users and computers, get current user SID or get local user SID using PowerShell Get-LocalUser cmdlet.

PowerShell Get-LocalUser cmdlet gets local user account, built-in account and user account details SID of user, user name and enabled status.

Get User SID in PowerShell
Get User SID in PowerShell

Let’s understand how to use Get-LocalUser in PowerShell to get SID of local user active directory cmdlets like Get-AdUser, Get-AdComputer and Get-AdGroup to find aduser SID, adcomputer SID and adgroup SID respectively with examples.

Get Current User SID in PowerShell

You can get current user SID in PowerShell using Get-LocalUser cmdlet which gets user account details, run below command to get currently logged in user SID

Get-LocalUser -Name $env:USERNAME | Select sid

In the above PowerShell script, Get-LocalUser gets user account details specified by environment variable $env:USERNAME and pass output to second command.

Second command get SID of current logged user as below

Get Current User SID PowerShell
Get Current User SID PowerShell

Get Local User SID in PowerShell

You can get local user SID in PowerShell using Get-LocalUser as below

Get-LocalUser -Name 'garyw' | Select sid

In the above PowerShell script, we specify local user name to get local user SID.

Get AdUser SID in Active Directory

You can get active directory user SID using Get-ADUser cmdlet which gets one or more aduser account details, run below command

 Get-AdUser -Identity toms | Select Name, SID, UserPrincipalName

In the above PowerShell script, Get-ADUser cmdlet get aduser SID specified by Identity parameter and select name, SID of aduser and userprincipalname in PowerShell.

Output of above script to get aduser SID as below

PS C:\Windows\system32> Get-AdUser -Identity toms | Select Name, SID, UserPrincipalName

Name      SID                             UserPrincipalName
----      ---                            -----------------
Tom Smith S-1-5-21-1326752099-4012446882-462961959-1103 [email protected]

Get Computer SID in Active Directory

You can get active directory computer SID using Get-AdComputer cmdlet gets one or more computer account details, run below command

 Get-AdComputer -filter * | select Name, SID

In the above PowerShell, Get-AdComputer cmdlet in active directory gets computer account details and use pipe operator to select computer name and SID of computer in active directory

PS C:\Windows\system32> get-adcomputer -filter * | select Name, SID

Name     SID
----     ---
ENGG-PRO S-1-5-21-1326752099-4012446882-462961959-1000
OPER-01  S-1-5-21-1326752099-4012446882-462961959-3104

Get AD Group SID in Active Directory

To get ad group SID in active directory, use Get-ADGroup cmdlet which gets one or more active directory groups, run below command to get ad group SID

Get-ADGroup -Identity SalesLeader | Select Name, SID

In the above PowerShell script, Get-AdGroup cmdlet get group account specified by Identity parameter and using pipe operator select Name and SID of ad group in active directory.

Output of above script to get adgroup SID as below

PS C:\Windows\system32> Get-ADGroup -Identity SalesLeader | Select Name, SID

Name        SID
----        ---
SALESLeader S-1-5-21-1326752099-4012446882-462961959-3105

Get SID of Domain in Active Directory

If you want to get Domain SID in PowerShell, use Get-AdDomain cmdlet of Active Directory, it has DomainSID attribute contains SID of domain.

Get-ADDomain -Identity SHELLPRO | Select Name, DomainSID

In the above PowerShell script, Get-AdDomain cmdlet gets domain information specified by Identity parameter and pipe output to Select Name and Domain SID in active directory

Get SID of all Domains in Active Directory

You can find SID of all domains in active directory using Get-AdForest cmdlet of active directory as below

(Get-ADForest).Domains| %{Get-ADDomain -Server $_}|select name, domainsid

Conclusion

I hope above article on how to get local user SID, get current user SID and find SID in active directory users and computers in PowerShell.

You can use Active Directory cmdlets like Get-ADUser, Get-AdComputer and Get-AdGroup to find SID in active directory users and computers, get ad user SID, ad computer SID using different cmdlet available in Active Directory.

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

Leave a Comment