Skip to content

$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). 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.

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

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

Name of the user to remove from the group.

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.

None.

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

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

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

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

$cs.UsrMgr_AddUserToLocalGroup $cs.UsrMgr_EnumMembersOfLocalGroup