I am writing a PowerShell script to get a list of certificates which are getting expired within 30 days. The script is working, but the problem is there are too many app and pre
Working with PS 4.0 or later, it´s possible to define as CheckCert([array]$ComputerNames)
as well.
Try this:
function CheckCert([string[]]$ComputerNames)
{
$deadline = (Get-Date).AddDays($global:threshold) # Set deadline date
foreach ($computer in $ComputerNames)
{
Invoke-Command -ComputerName $Computer { Dir Cert:\LocalMachine\My } |
foreach {
If ($_.NotAfter -le $deadline)
{
$_ | Select Issuer, Subject, NotAfter, @{N="Expires In (Days)";E={($_.NotAfter - (Get-Date)).Days}}
}
}
}
}