Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active October 30, 2018 04:50
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/dcc45b0a9f4c85cb7d2fae514747fc4e to your computer and use it in GitHub Desktop.
Save darrenjrobinson/dcc45b0a9f4c85cb7d2fae514747fc4e to your computer and use it in GitHub Desktop.
# 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