Last active
October 30, 2018 04:50
-
-
Save darrenjrobinson/dcc45b0a9f4c85cb7d2fae514747fc4e to your computer and use it in GitHub Desktop.
Delete SailPoint IdentityNow Objects from a Source. Associated Blog Post https://blog.darrenjrobinson.com/lifecycle-management-of-identities-in-sailpoint-identitynow-via-api-and-powershell/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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