So I am trying to create a report on my PKI Certs about to expire.
so I managed to create a html using the code bellow:
<#
.Synopsis
This Tool will query the Enterprise PKI and search for Certificates that matches a specific template that are expiring within a passed threshold and email a html report to a passed email
.Autor
Egberto Zanon
#>
# Check if the PSPKI 3.7.2 module is installed
$Module = Get-Module -ListAvailable -Name PSPKI -RequiredVersion 3.7.2
# If not, install it from the PowerShell Gallery for the current user only
if ( -not $Module ) {
Write-Host "Installing PSPKI 3.7.2 module..."
Install-Module -Name PSPKI -RequiredVersion 3.7.2 -Scope CurrentUser -Confirm:$false -Force
}
# Import the module
Import-Module -Name PSPKI
# Define days to alert
$Threshold = "30"
# Define the template name ( below is a invalida sample , add yours)
$TemplateName = "1.1.1.1.1.1.123.12.1.12345678.12345678.1234567.12345678.1234567.123.1234567.1234567"
# Get the current date
$Today = Get-Date
# Get the certificates from the enterprise PKI that match the template name
$Certificates = Get-CertificationAuthority | Get-IssuedRequest -Property CertificateTemplate, NotAfter | Where-Object { $_.CertificateTemplate -eq $TemplateName }
# Filter the certificates that are expiring within the threshold
#$ExpiringCertificates = $Certificates | Where-Object {$_.NotAfter -lt $Today.AddDays($Threshold)}
# Filter the certificates that are expiring within the threshold but haven't expired yet
$ExpiringCertificates = $Certificates | Where-Object { $_.NotAfter -gt $Today -and $_.NotAfter -lt $Today.AddDays($Threshold) }
Write-Output "Found $($ExpiringCertificates.count)"
# Check if there are any expiring certificates
if ($ExpiringCertificates) {
Write-Output "Emailing Report"
# Create a report object with the certificate details
$Report = $ExpiringCertificates | Select-Object RequestID, RequesterName, CommonName, NotAfter
# Convert the report object to HTML format
$HTMLReport = $Report | ConvertTo-Html -Title "Expiring Certificates Report" -PreContent "These are the certificates from the template that are expiring within $Threshold days on our enterprise PKI:"
}
and now I am trying import this information to a Solarwinds report page.
so I came up with the code bellow:
$moduleName = "SwisPowerShell"
# Check if the module is available, if not, install it
if (!(Get-Module -Name $moduleName -ListAvailable)) {
Install-Module -Name $moduleName -Force -AcceptLicense -Scope CurrentUser
}
$Securedcredential = get-credential
# Connect to the SolarWinds Information Service (SWIS) using the hostname, and $Securedcredential
$swis = Connect-Swis -Hostname "localhost" -Credential $Securedcredential
# Clean credentials from memory
Remove-Variable -Name Securedcredential
# Get the report ID of the report named "My Report" from the Orion.Report table
$report = Get-SwisData $swis "SELECT ReportID, Uri, Name FROM Orion.Report WHERE Name='COS PKI - Expiring Certs'"
# Assign the report ID to a variable
$ReportID = $report.ReportID
$reportUri = $report.Uri
$reportObject = Get-SwisObject $swis -Uri $reportUri
$reportObject.Type
# Define a hashtable of properties to update the report
$reportProperties = @{
CustomHtml = "$($HTMLReport)"
}
# Update the report object with the new properties
# $swis -Uri $reportUri -Properties $reportProperties -Debug
but I am getting the error on the Set-SwisObject: There are no key property mappings to locate a data provider.
Does anyone know what should I put here to update the custom html code on the report? or this is a no no and I will have to figure out another way?
thanks!



