Converting User Names to SIDs

by Nov 17, 2011

If you want to translate a valid user name to its security identifier (SID), here is a function to do that for you:

function Name2SID($name, $domain=$env:userdomain) {
    $objUser = New-Object System.Security.Principal.NTAccount($domain, $name)
    $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
    $strSID.Value
}

Try it with your current user name:

Name2SID $env:username

Twitter This Tip!
ReTweet this Tip!