Friday, March 31, 2017

Check for expired certificates using PowerShell (on multiple servers) SharePoint

$threshold = 30   #Number of days to look for expiring certificates

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

Invoke-Command -ComputerName BTGMVDCSPAPP01,BTGMVDCSPWEB01 { Dir Cert:\LocalMachine\My } | foreach {

If ($_.NotAfter -le $deadline) { $_ | Select Issuer, Subject, NotAfter, @{Label="Expires In (Days)";Expression={($_.NotAfter - (Get-Date)).Days}} }

}