This data source will retrieve a list of members for a group, given that group's name. The group's name is most often taken as input from a dropdown list.
This data source is typically used in conjunction with a list of all users in the domain, so as to populate a Dual List control for adding and removing members from the selected group. One side of the list contains all available users in the domain, while the other side of the list contains the current group members.
Create the data source task
- Navigate to Automation > Tasks.
- Create a new custom PowerShell task and name it "Data Source: List Active Directory group members".
- Select an appropriate agent pool to run the task.
- In the Task tab, deselect Use template.
- Paste in the following script and save the task.
# Accept input from the form $groupName = $formInput.selectedGroup.name try { # Retrieve members of the group $members = Get-ADGroupMember -Identity $groupName # Return the group members to HelloID foreach($user in $members) { $row = @{} $user.psobject.properties | Foreach { $row[$_.Name] = $_.Value.ToString() } Hid-Add-TaskResult -ResultValue $row } } catch { # Log message in case of an error $error_message = $Error[0].Exception Hid-Write-Status -Message $error_message -Event Information Hid-Add-TaskResult -ResultValue [] }
Create the data source
- Navigate to Self Service > Data sources.
- Create a new data source with the name "Active Directory group members".
- In the Type dropdown, select Task Data Source.
- Update the model so that it looks like the screenshot shown below.
- On the Input tab, add an input parameter with the key value of "selectedGroup".
- Save the data source.