Last active
May 6, 2021 19:17
-
-
Save darrenjrobinson/c5c833971d4cdf06f4326b3d0565b8bb to your computer and use it in GitHub Desktop.
SailPoint IdentityNow Source Configuration Report. Associated blog post https://blog.darrenjrobinson.com/creating-sailpoint-identitynow-source-configuration-backups-and-html-reports-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
# Document IdentityNow Source Configuration | |
# Get Source from SailPoint IdentityNow Module Config | |
$orgName = (Get-IdentityNowOrg).'Organisation Name' | |
$IDNSources = Get-IdentityNowSource | |
# Report SailPoint Logo Image | |
$reportImagePath = "C:\Reports\IdentityNow Source Reports\SailPoint IdentityNow 240px.png" | |
# Report Output Folder | |
$ReportOutputPath = "C:\Reports\IdentityNow Source Reports" | |
if ($IDNSources) { | |
write-host -ForegroundColor Green "$($IDNSources.Count) Sources found" | |
} | |
else { | |
Write-Error "Check configuration of the SailPointIdentityNow PowerShell Module. No Sources found" | |
} | |
try { | |
$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>" | |
} | |
catch { | |
Write-Error "Report Image Path/Filename not found" | |
break | |
} | |
$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 Configuration 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 = Get-IdentityNowSource -sourceID $source.id | |
if ($sourceDetails) { | |
# Output Source to File | |
$sourceDetails | Export-Clixml -Path "$($dir)\$($orgName)-$($source.name)-Details-$($reportDate).xml" | |
} | |
# Get Schema | |
$sourceSchema = $null | |
$sourceSchema = Invoke-IdentityNowRequest -Method Get -Uri "https://$($orgName).api.identitynow.com/cc/api/source/getAccountSchema/$($source.id)" -headers HeadersV3 | |
if ($sourceSchema) { | |
# Output Schema to File | |
$sourceSchema | Export-Clixml -Path "$($dir)\$($orgName)-$($source.name)-Schema-$($reportDate).xml" | |
} | |
# 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>" | |
# 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>" | |
} | |
} | |
# Footer | |
$htmlFragments += "<center><p class='footer'>Report Generated $(get-date)</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; overflow:hidden; max-width:480px; width:70%; margin:0 auto; position:relative;} | |
table, tr, td, th {padding: 10px; margin: 0px ;white-space:pre; word-break:break-all; width:70%;} | |
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; word-break:break-all; 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