Pages

Showing posts with label SID to User Name. Show all posts
Showing posts with label SID to User Name. Show all posts

Friday, April 10, 2020

Convert UserName to SID and SID to UserName

Convert UserName to SID and SID to UserName

Here is a simple PowerShell Script to convert a UserName to SID and SID to UserName. 
It can also be used to convert Local User Name to SID and Local SID to Local User Name.

######################################################################################
# Use this script to translate UserName to SID,                                
# SID to UserName and Local user to SID.                                       
# Script Written by Prakash Kumar (6th April 2020)                
######################################################################################

param($SID,
$ADUSER,
$LOCALUSER)

#Enter Your Domain Name Here:
$DOMAIN = "DomainName"

if ($SID)
    {
        $UserSID = New-Object System.Security.Principal.SecurityIdentifier("$SID")
        $UserID = $UserSID.Translate( [System.Security.Principal.NTAccount])
        Write-output "$SID `t : $UserID"
    }
ElseIf ($ADUSER)
    {
        $UserID = New-Object System.Security.Principal.NTAccount("$DOMAIN", "$ADUSER")
        $strSID = $UserID.Translate([System.Security.Principal.SecurityIdentifier])
        Write-output "$ADUSER `t : $strSID"
       
    }
ElseIf ($LOCALUSER)
    {
        $UserID = New-Object System.Security.Principal.NTAccount("$LOCALUSER")
        $strSID = $UserID.Translate([System.Security.Principal.SecurityIdentifier])
        Write-output "$LOCALUSER `t : $strSID"

    }

 Here is the screenshot from the above script: