If you’d need to find out the SID for a user name, here is a useful chunk of code that does the job:

$domain = 'MyDomain'
$username = 'User01'

$sid = (New-Object Security.Principal.NTAccount($domain, $username)).Translate([Security.Principal.SecurityIdentifier]).Value


Just make sure you adjust domain name and username accordingly. If you need to find the SID for local accounts, set the domain name to the name of the local machine.

$username = 'Administrator'

$sid = (New-Object Security.Principal.NTAccount($env:computername, $username)).Translate([Security.Principal.SecurityIdentifier]).Value


This is much easier in PowerShell 5, though, because of a new cmdlet called Get-LocalUser:

PS C:\> Get-LocalUser | Select-Object -Property Name, Sid

Name           SID                                           
----           ---                                           
Administrator  S-1-5-21-2951074159-1791007430-3873049619-500 
CCIE           S-1-5-21-2951074159-1791007430-3873049619-1000
DefaultAccount S-1-5-21-2951074159-1791007430-3873049619-503 
Guest          S-1-5-21-2951074159-1791007430-3873049619-501 

Twitter This Tip! ReTweet this Tip!