This data source will retrieve a user object from Active Directory when supplied with input from a User Selector form control. It will return the object and its associated properties to HelloID. This is useful when you want to show extended information about a particular user, either for display purposes or for updating the user's information.
Create the data source task
- Navigate to Automation > Tasks.
- Create a new custom PowerShell task and name it "Data Source: Get Active Directory user object"
- 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 Format-Volume $upn = $formInput.selectedUser.userName try { # Retrieve user from Active Directory. Add properties as necessary and update the data source model accordingly. $user = Get-ADUser -Filter {userPrincipalName -eq $upn} -Properties displayName, cn, canonicalName, whenCreated, lastLogonTimestamp if ($user) { # Return the user to HelloID. Add additional properties and formatting as neccessary. $userDescription = [ordered]@{ DisplayName = $user.displayName; CanonicalName = $user.canonicalName; CommonName = $user.cn; Enabled = $user.enabled; GivenName = $user.givenName; LastLogonTimestamp = ([DateTime]::FromFileTime($user.lastLogonTimestamp)).toString(); SamAccountName = $user.sAMAccountName; Surname = $user.sn; UserPrincipalName = $user.UserPrincipalName; WhenCreated = $user.whenCreated.toString(); } Hid-Add-TaskResult -ResultValue $userDescription } else { Hid-Write-Status -Message "User $upn not found" -Event Information } } catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { # 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 user information".
- 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 "selectedUser".
- Save the data source.