Instantly share code, notes, and snippets.

Embed
What would you like to do?
IdentityNow Certification Completion Status Reports. Associated Blog Post located here https://blog.darrenjrobinson.com/retrieving-sailpoint-identitynow-certification-reports-using-powershell/
$orgName = "myIDNOrg"
# Get Campaign Base URI
$GetCampaignBaseURI = "https://$($orgName).api.identitynow.com/cc/api/campaign/get"
# Get Reports Base URI
$getReportsBaseURI = "https://$($orgName).api.identitynow.com/cc/api/campaign/getReports"
# Get Completed Campaigns and Reports
$csvStatusReportBaseURI = "https://$($orgName).api.identitynow.com/cc/api/report/get"
# List Campaign Base URI
$GetCampaignBaseURI = "https://$($orgName).api.identitynow.com/cc/api/campaign/list"
# Export Reports from the last x Days
$daystoExport = "7"
$IDN.Headers.Remove("Content-Type")
$utime = [int][double]::Parse((Get-Date -UFormat %s))
# Completed Campaigns
$completedOnly = $true
$campaigns = 100
# Get Campaigns
$existingCampaigns = Invoke-RestMethod -method Get -uri "$($GetCampaignBaseURI)?_dc=$($utime)&completedOnly=$($completedOnly)&start=0&limit=$($campaigns)" -WebSession $IDN
foreach ($campaign in $existingCampaigns.items) {
# Get time of completion of the Campaign
$unixtime = $null
[string]$unixtime = $campaign.deadline
$unixtime = $unixtime.Substring(0, 10)
$time = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($unixtime))
$accesst = $idn.Headers.authorization.split(" ")
if ($time -gt (get-date).AddDays(-$($daystoExport))) {
$campaignReports = $null
$campaignReports = Invoke-RestMethod -Method Get -Uri "$($getReportsBaseURI)?_dc=$($utime)&campaignId=$($campaign.id)&page=1&start=0&limit=25&sort=%5B%7B%22property%22%3A%22name%22%2C%22direction%22%3A%22ASC%22%7D%5D" -WebSession $IDN
foreach ($report in $campaignReports) {
if ($report.name.Equals("Campaign Status Report")) {
write-host -ForegroundColor Green "The $($campaign.description) campaign is of type $($campaign.type) and was completed on $($time.Date.Day)/$($time.Date.Month)/$($time.Date.Year) with $($campaign.totalCertifications) certification(s)."
# Get CSV Report
$outputFile = "c:\temp\SailPointCampaignReports\$($campaign.description)-StatusReport.csv"
$report = Invoke-RestMethod -Method Get -Uri "$($csvStatusReportBaseURI)/$($report.taskResultId)?format=csv&name=Export+Campaign+Status+Report&url_signature=$($accesst[1])" -WebSession $IDN
# Output Report to filesystem
$report | out-file $outputFile
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment