Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/e589954a569b602817be9f310be8dc9c to your computer and use it in GitHub Desktop.
Save darrenjrobinson/e589954a569b602817be9f310be8dc9c to your computer and use it in GitHub Desktop.
Extract all accounts on a SailPoint IdentityNow Source. Associated blog post is located here https://blog.darrenjrobinson.com/searching-returning-all-objects-users-from-a-sailpoint-identitynow-source/
#Install-Module psInlineProgress
# Your API Client ID obtained via IDN Admin Portal
$clientID = "zo7GG51uABCDEFwv"
# Your API Client Secret obtained via IDN Admin Portal
$clientSecret = "3Zm123d4sWish3Lva9yCX9DIfmwABCD"
$Bytes = [System.Text.Encoding]::utf8.GetBytes("$($clientID):$($clientSecret)")
$encodedAuth = [Convert]::ToBase64String($Bytes)
# Your IdentityNow Tenant Name
$orgName = 'CompanyX'
# SourceID of the Source to get objects from
# Navigate to the Source in the IdentityNow Portal and get the SourceID from the URL
# https://<orgName>.identitynow.com/ui/admin#admin:connections:sources
$sourceID = '36666'
# Search Identities
$accountsURI = "https://$($orgName).api.identitynow.com/v2/accounts?sourceId=$($sourceID)"
$searchLimit = "2500"
# Search for Users by Source
$idnObjects = $null
if (!$idnObjects) {
# Get Base Users
$idnObjects = @()
$searchResults = Invoke-RestMethod -Method Get -Uri "$($accountsURI)&limit=$($searchLimit)&org=$($orgName)" -Headers @{Authorization = "Basic $($encodedAuth)" }
#"Search for accounts on SourceID: $($sourceID) returned $($searchResults.Count) account(s)"
if ($searchResults) {
$idnObjects += $searchResults
}
$offset = 0
do {
if ($searchResults.Count -eq $searchLimit) {
# Get Next Page
[int]$offset = $offset + $searchLimit
$searchResults = Invoke-RestMethod -Method Get -Uri "$($accountsURI)&limit=$($searchLimit)&offset=$($offset)&org=$($orgName)" -Headers @{Authorization = "Basic $($encodedAuth)" }
$searchResults.Count
"Search for accounts on SourceID: $($sourceID) returned $($searchResult.Count) account(s)"
if ($searchResults) {
$idnObjects += $searchResults
}
}
} until ($searchResults.Count -lt $searchLimit)
"Total accounts on SourceID: $($sourceID) is $($idnObjects.Count)"
}
# Collection of Full User Objects
$fullUsers = @()
[int]$i = 0
write-host -ForegroundColor Yellow "Retrieving full user records"
foreach ($obj in $idnObjects) {
$i++
#$global:user | Out-File $DebugFile -Append
if ($obj.id) {
$userDetails = $null
$usrDetailsURI = "https://$($orgName).api.identitynow.com/v2/accounts/$($obj.id)?org=$($orgName)"
$userDetails = Invoke-RestMethod -Method Get -Uri $usrDetailsURI -Headers @{Authorization = "Basic $($encodedAuth)" }
if ($userDetails) {
$fullUsers += $userDetails
}
}
# PS ISE Progress Bar
#Write-Progress -Activity "Retrieving User Object" -status "User $($obj.displayName)" -percentComplete ($i / $idnObjects.count * 100)
# VS Code Progress Bar
# get psInlineProgress using Install-Module psInlineProgress
# update line 36 of psInlineProgress.psd1 and change ConsoleHost to Visual Studio Code Host
$percentComplete = $i / $idnObjects.count * 100
Write-InlineProgress -Activity "Getting User Object $($obj.displayName)" -PercentComplete $percentComplete -ProgressCharacter '<' -ProgressFillCharacter '.' -ProgressFill '-'
}
write-host -ForegroundColor Green "Retrieved full user records for $($fullUsers.Count) users"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment