Skip to content

Instantly share code, notes, and snippets.

@Dimtemp
Last active November 4, 2023 12:52
Show Gist options
  • Save Dimtemp/00d85d67c1ae42c114eea9a8ac7efb44 to your computer and use it in GitHub Desktop.
Save Dimtemp/00d85d67c1ae42c114eea9a8ac7efb44 to your computer and use it in GitHub Desktop.
Check for certificate expiration
function Get-CertificateExpiration {
<#
.SYNOPSIS
Displays a list of certificates that will expire soon.
#>
param(
$Threshold = 30, #Number of days to look for expiring certificates
[string[]]$ComputerName
)
$Deadline = (Get-Date).AddDays($Threshold)
if ($ComputerName) {
$cert = Invoke-Command -ComputerName $ComputerName { Get-ChildItem Cert:\ -Recurse }
} else {
$cert = Get-ChildItem Cert:\ -Recurse
}
$cert | Foreach-Object {
If ($_.NotAfter -le $Deadline) {
$_ | Select-Object *, @{Name="Expires In (Days)"; Expression={($_.NotAfter - (Get-Date)).Days}}
# other interesting properties: Issuer, Subject, NotAfter
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment