In Windows environment, each domain and local user, a group or other security objects are assigned a unique identifier — Security Identifier or SID.
SID used to control access to different resources: network shares, registry keys, file system objects, etc.
Now we will see some simple ways to get SID by username and the reverse.
Convert Domain UserName to SID
The following command can be used to get an SID of the current domain account:
whoami /user
You can use Get-ADUser cmdlet being a part of Active Directory Module for Windows PowerShell
If you don’t have the AD Module for PowerShell, you can request data from the domain using PowerShell
$objUser = New-Object System.Security.Principal.NTAccount("corp.domain.com","Andriy.Zarevych")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
$strSID.Value
Or the same command in one line
(new-object security.principal.ntaccount “Andriy.Zarevych").translate([security.principal.securityidentifier])
Convert a SID to User Name
To get the name of the user account by the SID, you can use one of the following command
wmic useraccount where sid='S-1-2-12-1234534567-1234567890-1234567-1234' get name
Using AD Module for PowerShell
Get-ADUser -Identity S-1-2-12-1234534567-1234567890-1234567-1234
Or
$objSID = New-Object System.Security.Principal.SecurityIdentifier ("S-1-3-12-1234534567-1234567890-1234567-1234")
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$objUser.Value
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$objUser.Value
No comments:
Post a Comment