$cs.UsrMgr_EnumMembersOfLocalGroup
Description
Section titled “Description”Returns the members of a local group. The group parameter accepts either a group name or a SID (a SID is resolved to a name internally before enumeration). Each returned object exposes the member’s identity as a caption/name string.
Syntax
Section titled “Syntax”$cs.UsrMgr_EnumMembersOfLocalGroup(string group)
Parameters
Section titled “Parameters”group (String)
Section titled “group (String)”Name or SID of the local group to enumerate.
Return value
Section titled “Return value”A Collection<PSObject> listing the members of the group.
Example
Section titled “Example”Audit and log the current members of Administrators before making any changes, so the pre-install state is captured for troubleshooting:
$groupMembers = $cs.UsrMgr_EnumMembersOfLocalGroup('Administrators')foreach ($item in $groupMembers) { $cs.Job_WriteLog("Member found: $($item)")}Check whether a specific user is already a member of a group before adding them, to avoid redundant calls:
$members = $cs.UsrMgr_EnumMembersOfLocalGroup('S-1-5-32-544')$alreadyMember = $members | Where-Object { $_.ToString() -like '*capaadmin*' }
if (-not $alreadyMember) { $cs.Job_WriteLog("capaadmin is not yet a member of Administrators, adding it") $cs.UsrMgr_AddUserToLocalGroup('capaadmin', 'S-1-5-32-544')} else { $cs.Job_WriteLog("capaadmin is already a member of Administrators, skipping")}Related functions
Section titled “Related functions”$cs.UsrMgr_AddUserToLocalGroup $cs.UsrMgr_RemoveUserFromLocalGroup $cs.UsrMgr_GetNameBySid