# $cs.UsrMgr_RemoveUserFromLocalGroup

> Removes domain\userName from a local group. Pass . for domain to mean the local computer (it is normalized internally to the machine's own name).

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

### Description

Removes `domain\userName` from a local group. Pass `.` for `domain` to mean the local computer (it is normalized internally to the machine's own name). The `group` parameter accepts either a plain group name or a SID. If the user is not currently a member of the group, the function returns silently without error.

### Syntax

$cs.UsrMgr_RemoveUserFromLocalGroup(string domain, string userName, string group)

### Parameters

#### domain (String)

Domain of the user, or `.` for the local computer.

#### userName (String)

Name of the user to remove from the group.

#### group (String)

The group to remove the user from. Can be a plain group name or a SID. If the user is not a member, no error is raised.

### Return value

None.

### Example

**PowerShell**

Remove a domain user from the local `Administrators` group during cleanup:

```powershell
$cs.Job_WriteLog("Removing testuser from Administrators")
$cs.UsrMgr_RemoveUserFromLocalGroup('capasystems.com', 'testuser', 'Administrators')
```

Remove a local account, using `.` for the domain, from a custom application group when uninstalling:

```powershell
function Uninstall {
  $cs.Job_WriteLog("Removing capasupport from AppRemoteUsers")
  $cs.UsrMgr_RemoveUserFromLocalGroup('.', 'capasupport', 'AppRemoteUsers')
}
```

Remove a service account from the built-in Administrators group by SID, so the script is unaffected by locale or group renames:

```powershell
$cs.Job_WriteLog("Removing svc_capaagent from the local Administrators group")
$cs.UsrMgr_RemoveUserFromLocalGroup('.', 'svc_capaagent', 'S-1-5-32-544')
```

### Related functions

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