How To Grab Windows SIDs with PowerShell

There are those times where you just need those SIDs, no matter what door you knock on.
For those fateful times, you can use this snippet of code to grab the SID from a given target user.

#this is the target user name
$username = "SomeDomainSomeUserName";

# get the account object
$account = New-Object System.Security.Principal.NTAccount $username;

# then get the sid value from it
$sid = $account.Translate([System.Security.Principal.SecurityIdentifier]).Value;

# or just do it all at once
$sid = (New-Object System.Security.Principal.NTAccount $username).Translate([System.Security.Principal.SecurityIdentifier]).Value;

Index: PowerShell HowTo’s


Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s