How to get SID with PowerShell
Here is simple example of how to retrieve local NT account (user or group) SID with powershell:
PS E:\TEST> $objUser = New-Object System.Security.Principal.NTAccount("alesk") PS E:\TEST> $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) PS E:\TEST> $strSID.Value S-1-5-21-1384281309-654973799-88281384-1000
To retrieve SID of domain user:
PS E:\TEST> $objUser = New-Object System.Security.Principal.NTAccount("acmedomain\alesk") or PS E:\TEST> $objUser = New-Object System.Security.Principal.NTAccount("acmedomain","alesk") PS E:\TEST> $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) PS E:\TEST> $strSID.Value S-1-5-21-2377153150-1065022559-2428809875-3485
I found this tip among tips published on MS Technet Windows PowerShell tips.
Posted on 30.06.2011, in MS Windows and tagged powershell, windows. Bookmark the permalink. Comments Off on How to get SID with PowerShell.