locked
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:-

    $servers=$env:computername
     $result=@()

    foreach ($i in $servers)

    {

    $ErrorActionPreference="SilentlyContinue"

    $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]@{
    'Server'=$i;
    'Certificate'=$c.Issuer;
    'Expires'=$c.NotAfter

    })

    }

    }

    Write-Output $result

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

    Thanks,

    RG


    RG

    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.

    Cheers,

    happy coding!

    RG


    RG

    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,
    Lee

    Just do it.

    Tuesday, June 25, 2019 9:35 AM