PowerShell Script to convert SID to Domain User

From KlavoWiki
Jump to navigationJump to search

sid.ps1 is the script to run. sid.txt is the file the contains a list of the requird SIDs to be converted. Once the script is run it will generate a file called UID.txt that contains a list of the user accounts.

sid.ps1

#=========================================================================== 
# Author        : Syed Abdul Khader  
# Description   : Powershell Script to convert SID to UserName 
# Pre-requisite : SID.txt is the text file containing SID's to be resolved 
# Output File   : UID.txt 
#=========================================================================== 
Out-File UID.txt 
foreach ($SID in (Get-Content SID.txt)) 
{ 
    $objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID) 
    Try 
    { 
        $objUser = $objSID.Translate( [System.Security.Principal.NTAccount]) 
        $objUser.Value >>UID.txt 
    } 
    Catch 
    { 
        $SID >>UID.txt 
    } 
}