How to get the certificate's start and expiry date using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To get the certificate's start and expiry date using PowerShell, we first need to retrieve the certificate details using a thumbprint or other properties like friendly name, subject name, etc.

Let say we have a certificate thumbprint details. So we can use the below command to retrieve the certificate's Start and End date along with the days remaining for the certificate expiry.

Example

Get-ChildItem Cert:\LocalMachine\My\43E6035D120EBE9ECE8100E8F38B85A9F1C1140F `
   | Select @{N='StartDate';E={$_.NotBefore}},
   @{N='EndDate';E={$_.NotAfter}},
   @{N='DaysRemaining';E={($_.NotAfter - (Get-Date)).Days}}

Output

StartDate               EndDate                DaysRemaining
---------               -------                -------------
3/11/2021 1:58:12 AM    6/11/2021 3:08:10 AM            88

Here, NotBefore mentions the start date of the certificate while the NotAfter property mentions the end date of the certificate.

raja
Published on 18-Mar-2021 07:37:04
Advertisements