Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete SailPoint IdentityNow Objects from a Source
# Your API Client ID
$clientID = 'yourClientID'
# Your API Client Secret
$clientSecret = 'yourClientSecret'
$Bytes = [System.Text.Encoding]::utf8.GetBytes("$($clientID):$($clientSecret)")
$encodedAuth = [Convert]::ToBase64String($Bytes)
# Your IdentityNow Tenant Name
$orgName = 'yourTenantOrgName'
# Search URI
$URI = "https://$($org).api.identitynow.com/v2/search/identities?"
# Delete Base URI
$deleteBaseURI = "https://$($org).api.identitynow.com/v2/accounts/"
# Search Query for Accounts to Delete
$query = 'familyName EQ Sanchez'
# Search Accounts
$searchResults = Invoke-RestMethod -Method Get -Uri "$($URI)limit=$($searchLimit)&query=$($query)" -Headers @{Authorization = "Basic $($encodedAuth)" }
$searchResults.Count
write-host "$($searchResults.Count) found"
if ($searchResults.Count -gt 0) {
foreach ($identity in $searchResults) {
$id = $null
Write-host "Deleting $($identity.displayName)"
foreach ($account in $identity.accounts) {
If ($account.source.name.Equals("External Entities")) {
$id = $account.id
}
}
if ($id) {
$deleteURI = "$deleteBaseURI$($id)?org=$($orgName)"
try {
Invoke-RestMethod -Uri $deleteURI -Method Delete -Headers @{Authorization = "Basic $($encodedAuth)"; 'Content-Type' = 'application/json' }
}
catch {
write-host -forgroundcolor yellow "Well, that didn't work. Check your script"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment