Username to Security Identifier (SID)

The following example again shows the huge benefits of PowerShell allowing you to simply use .NET objects and methods. In many cases, you may want to search for the SIDs for specific users in your domain. This can be achieved by using the NTAccount object, as follows:

$domain = 'exampleDomain'
$username = 'David'

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

$sid
$username = 'Administrator'

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

$sid
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset