You might come across the object sid value in Active Directory environment. We can use the .NET Framework class System.Security.Principal.SecurityIdentifier in Windows PowerShell script to translate security identifier (SID) to user name and we can use the class System.Security.Principal.NTAccount to translate user name to security identifier (SID).
Convert SID to Username using Powershell
The below powershell script converts security identifier (SID) to user name. You can replace the variable $SID with your own sid value that you want to translate into user name.
$SID ='S-1-5-21-1924530255-1943933946-939161726-500' $objSID = New-Object System.Security.Principal.SecurityIdentifier($SID) $objUser = $objSID.Translate([System.Security.Principal.NTAccount]) Write-Host "Resolved user name: " $objUser.Value
Convert Username to SID using Powershell
The below powershell script converts user name to security identifier (SID). You can replace the variable $user with your own user account that you want to translate into sid.
$user ='TestDomainMorgan' $objUser = New-Object System.Security.Principal.NTAccount($user) $objSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) Write-Host "Resolved user's sid: " $objSID.Value
Advertisement