Last active
September 12, 2018 05:15
-
-
Save darrenjrobinson/bbfaff70a0491212866b42921426b863 to your computer and use it in GitHub Desktop.
Bulk Creation of Users in SailPoint IdentityNow with 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' | |
# SourceID of the Flat File Source to create the new account against. | |
# 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 = 'yourSourceID' | |
$baseURI = "https://$($orgName).api.identitynow.com" | |
$headers = @{'Content-Type' = 'application/json'; | |
Authorization = "Basic $($encodedAuth)"; | |
} | |
# Dataset names and address source files from https://github.com/darrenjrobinson/Generate-Random-Users | |
# Dataset Directory | |
$datasetDirectory = 'C:\Users\Darren Robinson\Powershell\Dataset' | |
# Female Firstnames | |
$femaleFirstnames = "firstnames-femalecy2017top.csv" | |
# Male Firstnames | |
$MaleFirstnames = "firstnames-malecy2017top.csv" | |
# Surnames | |
$surnamesList = "Surnames.csv" | |
# Postcodes | |
$postCodesList = "australian_postcodes.csv" | |
# Streetnames | |
$streetNamesList = "streetnames.csv" | |
# Female Firstnames | |
if ("$($datasetDirectory)\$($femaleFirstnames)") { | |
$fFirstNames = Import-Csv -Delimiter "," -Path "$($datasetDirectory)\$($femaleFirstnames)" | foreach { | |
New-Object PSObject -prop @{ | |
GivenName = (Get-Culture).textinfo.totitlecase($_.'Given Name'.tolower()); | |
} | |
} | |
} | |
# Male Firstnames | |
if ("$($datasetDirectory)\$($maleFirstnames)") { | |
$mFirstNames = Import-Csv -Delimiter "," -Path "$($datasetDirectory)\$($maleFirstnames)" | foreach { | |
New-Object PSObject -prop @{ | |
GivenName = (Get-Culture).textinfo.totitlecase($_.'Given Name'.tolower()); | |
} | |
} | |
} | |
# Combine Male and Female firstnames | |
$firstnames = $mFirstNames + $fFirstNames | |
$firstnames.Count | |
# Surnames | |
if ("$($datasetDirectory)\$($surnamesList)") { | |
$surnames = Import-Csv -Delimiter "," -Path "$($datasetDirectory)\$($surnamesList)" | foreach { | |
New-Object PSObject -prop @{ | |
Surname = (Get-Culture).textinfo.totitlecase($_.'Surnames'.tolower()); | |
} | |
} | |
} | |
# PostCodes | |
if ("$($datasetDirectory)\$($postcodesList)") { | |
$postcodes = Import-Csv -Delimiter "," -Path "$($datasetDirectory)\$($postcodesList)" | foreach { | |
New-Object PSObject -prop @{ | |
Postcode = $_.'postcode'; | |
Suburb = $_.'locality'; | |
State = $_.'state'; | |
} | |
} | |
} | |
# Street Names List | |
if ("$($datasetDirectory)\$($streetnamesList)") { | |
$streetnames = Import-Csv -Delimiter "," -Path "$($datasetDirectory)\$($streetnamesList)" | foreach { | |
New-Object PSObject -prop @{ | |
Streetname = (Get-Culture).textinfo.totitlecase($_.'STREET_NAME'.tolower()); | |
} | |
} | |
} | |
# Create 50 Users | |
# Update for number required | |
1..50 | % { | |
$randGivenName = Get-Random $firstnames.Count | |
$randSurname = Get-Random $surnames.Count | |
$randPostcode = Get-Random $postcodes.Count | |
$randStreet = Get-Random $streetnames.Count | |
$givenName = $firstnames[$randGivenName].GivenName | |
$surname = $surnames[$randSurname].Surname | |
$street = $streetnames[$randStreet].Streetname | |
$postcode = $postcodes[$randPostcode].Postcode | |
$suburb = $postcodes[$randPostcode].Suburb | |
$state = $postcodes[$randPostcode].State | |
$streetNumber = (Get-Random -Minimum 1 -Maximum 1000) | |
# NOTE: street, postcode, suburb, state added to the Source Schema | |
$body = @{"id" = "$($givenName).$($surname)"; | |
"name" = "$($givenName).$($surname)"; | |
"givenName" = $givenName; | |
"familyName" = $surname; | |
"displayName" = "$($givenName) $($surname)"; | |
"street" = "$([string]$streetNumber) $($street)"; | |
"postcode" = $postcode; | |
"suburb" = $suburb; | |
"state" = $state; | |
"country" = "Australia"; | |
"email" = "$($givenName).$($surname)`@customer.com.au" | |
} | |
$body = $body | ConvertTo-Json | |
$body | |
# API Call to create user here | |
# Create user | |
try { | |
Invoke-RestMethod -Method POST -Uri "$($baseURI)/v2/accounts?sourceId=$($sourceID)&org=$($orgName)" -Headers $headers -Body $body | |
} | |
catch { | |
write-host -ForegroundColor 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