# $cs.UsrMgr_GetNameBySid

> Resolves a Windows SID to its account name, e.g. DOMAIN\username or BUILTIN\Administrators.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-usrmgr-getnamebysid/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### 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

$cs.UsrMgr_GetNameBySid(string SID)

### Parameters

#### SID (String)

The SID to resolve to an account name.

### Return value

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

### Example

**PowerShell**

```powershell
$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:

```powershell
$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")
  }
}
```

### Related functions

[$cs.UsrMgr_EnumMembersOfLocalGroup](/capainstaller/powerpacks/cs-usrmgr-enummembersoflocalgroup/)
