Wednesday, September 13, 2017

Easy powershell function to resolve SIDs to SamAccountNames

Powershell function:

Function f-sid {
param ( [Parameter(Mandatory=$true)][String]$Sid)
$objSID = New-Object System.Security.Principal.SecurityIdentifier($Sid)
Try {
($objSID.Translate( [System.Security.Principal.NTAccount])).value
}
Catch {
Write-host “`nCouldn’t find any entry matching SID : $Sid” -foregroundcolor cyan
}
}


To use it:

> f-sid [yourSID]

if you have a list of SIDs in a txt file SIDs.txt

> get-content SIDs.txt | % { f-sid $_ }


NOTE: I did not write this, Brian did.

https://blogs.msmvps.com/ad/blog/2010/10/07/using-powershell-to-resolve-sids-to-friendly-names-2/

Thanks Brian.

No comments:

Blog Archive