Handy little function: Translate-SID

Ever come across something like this: S-1-5-21-9378569023-29138639125-19468 and wonder what it is? Try feeding it to this handy little function:

function Translate-SID
 $objSID = New-Object System.Security.Principal.SecurityIdentifier($SID)
 $objUser = $objSID.Translate([System.Security.Principal.NTAccount])
 Return $objUser.Value

Of course, you might feel the need to reverse this process and turn something perfectly fine like DOMAINUser into the illegible garbage that is known as a SID. Well, have it your way:

function Translate-ToSID
 $objID = New-Object System.Security.Principal.NTAccount($ID)
 $objSID = $objID.Translate([System.Security.Principal.SecurityIdentifier])
 Return $objSID.Value

Have a good one.