Applications such as System Center Operations Manager, SolarWinds and others give you warning when certificates are going to expire so it gives you chance to update them before services or applications are disrupted.
I put together a PowerShell script that will pull all the certificates on a machine and give you this information if your organization is not running the enterprise applications. The script creates a CSV file in a location that you need to specify and this is the output of the CSV file:
The script was tested in PowerShell ISE and PowerShell as well as the Exchange Management Shell on Exchange Server 2019 and it ran without error. Here is a snippet from an Exchange 2019 Server:
SCRIPT
There is only one place that needs to be updated in the script and this is on line 34, the following needs to be modified:
- $outputFilePath – Specify where you want to save the file
Here is the script you can use to generate the information:
# Function to generate a report for certificates
function Generate-CertificateReport {
param (
[string]$outputPath
)
# Get all certificates from the local machine store
$certificates = Get-ChildItem -Path Cert:\LocalMachine\My
# Create an array to store certificate information
$certificateInfo = @()
# Loop through each certificate and retrieve relevant information
foreach ($cert in $certificates) {
$certInfo = [PSCustomObject]@{
Subject = $cert.Subject
Thumbprint = $cert.Thumbprint
Issuer = $cert.Issuer
NotBefore = $cert.NotBefore
NotAfter = $cert.NotAfter
}
# Add certificate information to the array
$certificateInfo += $certInfo
}
# Export the certificate information to a CSV file
$certificateInfo | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Certificate report generated successfully. Path: $outputPath"
}
# Specify the path where you want to save the report
$outputFilePath = "C:\Installs\CertificateReport.csv"
# Call the function to generate the certificate report
Generate-CertificateReport -outputPath $outputFilePath
If you want to schedule this to run, you can add a scheduled task to send you the information when required such as the last day of every month.
Hope you find it helpful.