Convert-SIDtoACName.psm1
<#
.Synopsis Convert SID to account name .DESCRIPTION This command enables you to know the account name of the given SID. .PARAMETER SID Specifies the SID of the Active Directory object .EXAMPLE Convert-SIDtoACName -SID S-1-5-21-725345543-2052111302-527237000-773150 SID AccountName --- ----------- S-1-5-21-725345543-2052111302-527237000-773150 CloudComputee\Admin$ This is the example for a successful finding .EXAMPLE Convert-SIDtoACName -SID S-1-5-21-725345543-2052111302-527237000-770050 SID AccountName --- ----------- S-1-5-21-725345543-2052111302-527237000-770050 SID NOT FOUND This is the example when the command not able to find any SID in the entire directory .INPUTS ActiveDirectory object's SID .OUTPUTS Account name of the SID .NOTES .COMPONENT AD, ADSIEDIT .ROLE Domain User. Usually everyone in an organization would have read access to AdsiEdit .FUNCTIONALITY Fetching/ finding the account name of the given SID #> function Convert-SIDtoACName { Param( [Parameter(Mandatory=$true)][String[]]$SID ) [Array]$OutputTable = @() foreach($SID_ in $SID) { try { $objSID = New-Object System.Security.Principal.SecurityIdentifier($SID_) } catch{} try { $objUser = $objSID.Translate([System.Security.Principal.NTAccount]) } catch{} if($objUser.Value) { $Table = New-Object PSObject -Property @{ SID = $SID_; AccountName = $objUser.Value } } else { $Table = New-Object PSObject -Property @{ SID = $SID_; AccountName = 'SID NOT FOUND' } } $OutputTable+= $Table } Return $OutputTable } |