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