# $cs.UsrMgr_DeleteLocalUserAccount

> Deletes a local user account. Accepts either a plain user name or a SID.

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

### Description

Deletes a local user account. Accepts either a plain user name or a SID. If the user does not exist, the function returns silently without error.

### Syntax

$cs.UsrMgr_DeleteLocalUserAccount(string userName)

### Parameters

#### userName (String)

The local user account to delete. Can be a plain user name or a SID. If the account does not exist, no error is raised.

### Return value

None.

### Example

**PowerShell**

```powershell
if ($cs.UsrMgr_ExistLocalUserAccount('capauser')) {
  $cs.Job_WriteLog("Removing local user capauser")
  $cs.UsrMgr_DeleteLocalUserAccount('capauser')
  # or by SID:
  $cs.UsrMgr_DeleteLocalUserAccount('S-1-5-21-3559337461-1037079836-4233830826-1109')
}
```

Clean up a temporary account created during install, as part of `PostUninstall`:

```powershell
function PostUninstall {
  if ($cs.UsrMgr_ExistLocalUserAccount('capa_tempinstall')) {
    $cs.Job_WriteLog("Removing temporary install account capa_tempinstall")
    $cs.UsrMgr_DeleteLocalUserAccount('capa_tempinstall')
  }
}
```

Delete an account by SID when the account name may have been changed or localized after creation:

```powershell
$accountSid = 'S-1-5-21-3559337461-1037079836-4233830826-1109'
if ($cs.UsrMgr_ExistLocalUserAccount($accountSid)) {
  $cs.Job_WriteLog("Removing local account with SID $accountSid")
  $cs.UsrMgr_DeleteLocalUserAccount($accountSid)
}
```

### Related functions

[$cs.UsrMgr_CreateLocalUser](/capainstaller/powerpacks/cs-usrmgr-createlocaluser/) [$cs.UsrMgr_ExistLocalUserAccount](/capainstaller/powerpacks/cs-usrmgr-existlocaluseraccount/)
