$cs.UsrMgr_GetNameBySid
Description
Section titled “Description”Resolves a Windows SID to its account name, e.g. DOMAIN\username or BUILTIN\Administrators. Returns an empty string if the SID cannot be resolved to a name.
Syntax
Section titled “Syntax”$cs.UsrMgr_GetNameBySid(string SID)
Parameters
Section titled “Parameters”SID (String)
Section titled “SID (String)”The SID to resolve to an account name.
Return value
Section titled “Return value”[string] The resolved account name, or an empty string if the SID could not be resolved.
Example
Section titled “Example”$accountName = $cs.UsrMgr_GetNameBySid('S-1-5-21-3559337461-1037079836-4233830826-1109')if ($accountName) { $cs.Job_WriteLog("SID resolved to $accountName")}Resolve the SID of the first user profile found under the ProfileList registry key to a friendly name for logging purposes. This is a profile on the computer, not necessarily the user who is logged on now:
$profileKey = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' | Where-Object { (Get-ItemProperty $_.PSPath).ProfileImagePath -like 'C:\Users\*' } | Select-Object -First 1
if ($profileKey) { $profileSid = $profileKey.PSChildName $profileName = $cs.UsrMgr_GetNameBySid($profileSid) if ($profileName) { $cs.Job_WriteLog("Found user profile: $profileName") } else { $cs.Job_WriteLog("Could not resolve profile SID $profileSid") }}