<< Back to Script Library

Computer Certificate Expiration Check

Checks for X.509 certificates in the LocalMachine store that will expire in a certain number of days.
Version: 1.3.4
Created: 2015-02-18
Modified: 2015-02-18
Creator: Prakash Banuka
Downloads: 294
Tags: certificates
The Script Copy Script Copied to clipboard

$threshold = $args[0]

#Set deadline date
$deadline = (Get-Date).AddDays($threshold)

$Certs = Get-ChildItem Cert:\LocalMachine\My | where {$_.notafter -lt $deadline} |
    select issuer, subject,notafter, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}}

If ($Certs) {$Certs} Else { Write-Host "There are no certificates expiring in $Threshold days." }