Skip to content

$cs.UsrMgr_GetNameBySid

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.

$cs.UsrMgr_GetNameBySid(string SID)

The SID to resolve to an account name.

[string] The resolved account name, or an empty string if the SID could not be resolved.

Terminal window
$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:

Terminal window
$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")
}
}

$cs.UsrMgr_EnumMembersOfLocalGroup