how to get expiration date of a particular certificate through Powershell RRS feed

  • Question

  • Hi Folks,

    I am trying to create a power shell script that will provide me output of expiration date of a particular certificate.

    I was able to extract the information for all certificate but while trying to get the value for a specific certificate through its friendly name it's not happening.

    Below is my Script through which I am getting all certificate information:-


    foreach ($i in $servers)



    $a=Invoke-Command -ComputerName $i {Get-ChildItem Cert:\LocalMachine\My -Recurse |
    Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and $_.NotAfter -gt (Get-Date) -and $_.NotAfter -lt (Get-Date).AddDays(3000)}


    foreach ($c in $a) {

    $result+=New-Object -TypeName PSObject -Property ([ordered]@{




    Write-Output $result

    Note: I tried to get the value through friendly name but it is also not working .




    Monday, June 24, 2019 9:18 AM

All replies

  • Hi Team,

    I was able to get the desired output as I put one more add condition in the Invoke command.


    happy coding!



    Monday, June 24, 2019 9:41 AM
  • Hi,

    I am glad to hear that your issue was successfully resolved. If there is anything else we can do for you, please feel free to post in the forum.

    Best Regards,

    Just do it.

    Tuesday, June 25, 2019 9:35 AM