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 currently logged-on user’s SID from their profile registry key to a friendly name for logging purposes:

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) {
$loggedOnSid = $profileKey.PSChildName
$loggedOnName = $cs.UsrMgr_GetNameBySid($loggedOnSid)
if ($loggedOnName) {
$cs.Job_WriteLog("Installing for logged-on user: $loggedOnName")
} else {
$cs.Job_WriteLog("Could not resolve logged-on user SID $loggedOnSid")
}
}

$cs.UsrMgr_EnumMembersOfLocalGroup