1

I know how to do this normally, but the problem is all of the certs in question are not installed on my local machine. I have a source control directory where they all sit, and I need to iterate over them with powershell to find which have expired. There's too many to just double click on to view the "Valid from" information, so how can I get that using powershell?

4
  • 1
    Are they public, digicert has a free notification system Commented Nov 25, 2015 at 16:28
  • 1
  • Check out openssl it has a load of functions that can probably do that for you
    – Phil
    Commented Nov 25, 2015 at 17:31
  • 2
    OpenSSL? Really? There is no need in OpenSSL, when PowerShell does this natively. Especially when the talk is about Windows platform.
    – Crypt32
    Commented Nov 25, 2015 at 18:13

2 Answers 2

3

I was playing with certificates and came across this, I wasn't able to get the above code to work but I modified it to use GCI and filter and it worked, thanks !

gci C:\Users\myname\Documents\OT -Filter *.cer | 
%{
    $cert = New-Object Security.Cryptography.X509Certificates.X509Certificate2 $_.FullName
    if ($cert.NotAfter -lt (Get-Date)) {
        Write-Warning "$_ is expired"
    }
}
1

If they are stored in files, then you can instantiate an X509Certificate2 object from file and then check expiration date as usually:

dir c:\certs -Include *.cer, *.crt | %{
    $cert = New-Object Security.Cryptography.X509Certificates.X509Certificate2 $_.FullName
    if ($cert.NotAfter -lt (Get-Date)) {
        Write-Warning "$_ is expired"
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .