Determining the SID for a Local User Account
Here’s a simple script that returns the SID for a local user named mozaid:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$objUser = New-Object System.Security.Principal.NTAccount("mozaid") | |
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) | |
$strSID.Value |
Determining the SID for an Active Directory User Account
You can use the exact same approach to determine an Active Directory SID as you do for local user SID; the only thing is to include both the domain (fabrikam) and the user name (mozaid):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$objUser = New-Object System.Security.Principal.NTAccount("domain", "mozaid") | |
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) | |
$strSID.Value |