Friday, November 18, 2011

Converting User Names to SIDs using PowerShell

 

PowerTip of the Day, from PowerShell.com: 

Converting User Names to SIDs

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

 

Converting User Names to SIDs

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

 

Note: Tip copied from PowerShell.com

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.