Turning SIDs into Real Names

by Nov 18, 2011

Sometimes, you'd like to turn security identifiers (SIDs) into real names. Here is a function that can do this for you:

function SID2Name($sid){
  $objSID = New-Object System.Security.Principal.SecurityIdentifier($sid)
  try {
  $objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
  $objUser.Value
  } catch { $sid }
}

And, here is a show case for the function: to enumerate all profiles on your computer, you can read them from the Registry. However, all profiles are stored with SIDs only. Thanks to your new function, you can now display the real user names of everyone who has a profile on your machine:

function Get-Profile {
  $key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
  dir $key -Name | ForEach-Object { SID2Name $_ }
}

Twitter This Tip!
ReTweet this Tip!