Skip to content

Instantly share code, notes, and snippets.

@jdmills-edu
Created October 10, 2017 02:47
Show Gist options
  • Save jdmills-edu/d7bfd3e897725ca959a83760f2110f79 to your computer and use it in GitHub Desktop.
Save jdmills-edu/d7bfd3e897725ca959a83760f2110f79 to your computer and use it in GitHub Desktop.
A PowerShell script that lists all users in a Qualtrics tenant. Supports pagination and filtering by user type.
param(
[ValidateSet("all","admins")][String]$type = "all"
)
#Define connection parameters and API endpoints
$headers = @{
"X-API-TOKEN" = yourapitokenhere
}
$qualtrics_api_url = "https://yourdatacenter.qualtrics.com/API/v3"
$endpoint = "users"
$uri = $qualtrics_api_url+"/"+$endpoint
$users = @()
$result = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers
$users += $result.result.elements
#Pagination
while($result.result.nextPage){
$result = Invoke-RestMethod -Method Get -Uri $result.result.nextPage -Headers $headers
$users += $result.result.elements
Write-Host "." -ForegroundColor Green -NoNewline
}
#Sorting and filtering.
$users = $users | sort username
$admins = $users | where userType -eq "UT_BRANDADMIN"
#Return a user type based on the type parameter.
switch($type){
"all"{return $users}
"admins"{return $admins}
default{return $users}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment