Instantly share code, notes, and snippets.

Embed
What would you like to do?
SailPoint IdentityNow Source Config Backup and Report. Associated Blog Post can be found here https://blog.darrenjrobinson.com/creating-sailpoint-identitynow-source-configuration-backups-and-html-reports-with-powershell/
# Remove Content-Type otherwise repsonse from IDN Sources API complains about missing ID or Name in request. Go figure.
$Global:IDN.Headers.Remove("Content-Type")
$IDNSources = Invoke-RestMethod -Method Get -Uri "https://$($orgName).api.identitynow.com/cc/api/source/list" -WebSession $IDN
write-host -ForegroundColor Green "$($IDNSources.Count) Sources found"
$sourceDetailsURI = "https://$($orgName).api.identitynow.com/cc/api/source/get"
$sourceSchemaURI = "https://$($orgName).api.identitynow.com/cc/api/source/getAccountSchema"
# Report Image Settings
$reportImagePath = "C:\Users\darrenjrobinson\IdentityNow Source Reports\SailPoint IdentityNow 240px.png"
$ImageData = [Convert]::ToBase64String((Get-Content $reportImagePath -Encoding Byte))
$ImageFile = Get-Item $reportImagePath
$ImageType = $ImageFile.Extension.Substring(1) #strip off the leading .
$ImageTag = "<Img src='data:image/$ImageType;base64,$($ImageData)' Alt='$($ImageFile.Name)' width='240' height='82' hspace=10>"
$ReportOutputPath = "C:\Users\darrenjrobinson\IdentityNow Source Reports"
$reportDate = get-date -format "dd-MMM-yyyy HH-mm"
# Create Folder for Output in Path provided above with Report Date
$dir = "$($ReportOutputPath)\$($reportDate)"
if(!(Test-Path -Path $dir )){
New-Item -ItemType directory -Path $dir
}
# Build up the HTML Report
$htmlFragments = @()
# Headings and Title
$top = @"
<center>
<h1>SailPoint IdentityNow Source Report</h1>
<h2>Organisation - `'$($orgName.ToUpper())`'</h2>
<h3>`'$($IDNSources.Count)`' Sources found<h3>
<b><center>$ImageTag</center></b>
</center>
"@
$htmlFragments += $top
$h2Text = "IdentityNow Source Configuration"
$div = $h2Text.Replace(" ", "_")
$htmlFragments += "<center><a href='javascript:toggleDiv(""$div"");' title='click to collapse or expand this section'><h2>$h2Text</h2></a><div id=""$div""><a href='javascript:toggleAll();' title=' Click to toggle all sections'>+ / -</a></center>"
# Get Sources and Build the HTML Report
if ($IDNSources) {
foreach ($source in $IDNSources) {
# Sources
Write-host -ForegroundColor Blue " Retrieving $($source.name) Source Configuration"
# Get Detailed Source
$sourceDetails = Invoke-RestMethod -Uri "$($sourceDetailsURI)/$($source.id)" -Method Get -WebSession $Global:IDN
# Get Schema
$sourceSchema = $null
$sourceSchema = Invoke-RestMethod -Uri "$($sourceSchemaURI)/$($source.id)" -WebSession $Global:IDN
# Source Title
$H3Text = "$($source.name)"
$div = $H3Text.Replace(" ", "_")
$htmlFragments += "<a href='javascript:toggleDiv(""$div"");' title='click to collapse or expand this section'><center><h3>$H3Text</h3></center></a><div id=""$div"" style=""display: none;"">"
# Source Details
$H4Text = "$($source.name) Details"
$div = $H4Text.Replace(" ", "_")
$htmlFragments += "<a href='javascript:toggleDiv(""$div"");' title='click to collapse or expand this section'><center><h4>$H4Text</h4></center></a><div id=""$div"" style=""display: none;"">"
$htmlFragments += "<center>"
$htmlFragments += $sourceDetails | ConvertTo-Html -As LIST
$htmlFragments += "</center>"
$htmlFragments += "</div>"
# Output Details to File
$sourceDetails | Export-Clixml -Path "$($dir)\$($orgName)-$($source.name)-Details-$($reportDate).xml"
# Schema Details
$H4Text = "$($source.name) Schema Attributes"
$div = $H4Text.Replace(" ", "_")
$htmlFragments += "<a href='javascript:toggleDiv(""$div"");' title='click to collapse or expand this section'><center><h4>$H4Text</h4></center></a><div id=""$div"" style=""display: none;"">"
$htmlFragments += "<center>"
$htmlFragments += $sourceSchema | Select-Object $_ -ExpandProperty attributes | ConvertTo-Html -Fragment -Property Name,description,type,displayAttribute,entitlement,identityAttribute,managed,minable,multi
$htmlFragments += "</center>"
$htmlFragments += "</div>"
$htmlFragments += "</div>"
# Output Schema to File
$sourceSchema | Export-Clixml -Path "$($dir)\$($orgName)-$($source.name)-Schema-$($reportDate).xml"
}
}
# Footer
$htmlFragments += "<center><p class='footer'>Report Generated $($reportDate)</p></center>"
# Header
$head = @"
<Title>SailPoint IdentityNow Source(s) Report - $($orgName.ToUpper())</Title>
<style>
body {background-color:#ffffff; font:70%/1.5em Lato,sans-serif; padding:10px }
td,th {padding-left:8px}
th {color:black; background-color:cornflowerblue;}
table {border-spacing:1px; border-collapse:collapse; background:#F7F6F6; border-radius:6px; max-width:480px; width:70%; margin:0 auto; position:relative;}
table, tr, td, th {padding: 10px; margin: 0px ;white-space:pre; overflow-wrap: break-word; width:50%;}
tr:nth-child(even) {background-color:#dae5f4;}
tr:nth-child(odd) {background:#b8d1f3;}
thead tr {height:60px;background:#367AB1;color:#F5F6FA;font-size:1.2em;font-weight:700;text-transform:uppercase}
tbody tr {height:35px;border-bottom:1px solid #367AB1; overflow-wrap: break-word; text-transform:capitalize; font-size:1em;}
h1 {font-family:Tahoma;color:#A9A9A9;}
h2 {font-family:Tahoma;color:#6D7B8D;}
h3 {font-family:Tahoma;color:#6D7B8D;}
.alert {color: red;}
.footer {color:green; margin-left:10px; font-family:Tahoma; font-size:8pt; font-style:italic;}
.transparent {background-color:#ffffff;}
</style>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'>
</script>
<script type='text/javascript'>
function toggleDiv(divId) {
`$("#"+divId).toggle();
}
function toggleAll() {
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
var div = divs[i];
`$("#"+div.id).toggle();
}
}
</script>
"@
# Output the Report
$convertParams = @{
head = $head
body = $htmlFragments
}
convertto-html @convertParams | out-file -FilePath "$($dir)\$($orgName)-ConfigReport-$($reportDate).html"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment