Test Certicates on Servers

$servernames = ‘<servername>’

$servername=”
foreach ($servername in $servernames) {
Invoke-Command -ComputerName  $servername -ScriptBlock  {Get-ChildItem Cert:LocalMachineMy  |

Where-Object {$_.NotAfter -lt  (Get-Date).AddDays(365)}} | ForEach-object {
[pscustomobject]@{
Computername =  $_.PSComputername
Subject =  $_.Subject
ExpiresOn =  $_.NotAfter
DaysUntilExpired = Switch ((New-TimeSpan -End $_.NotAfter).Days) {
{$_  -gt 0} {$_}
Default  {‘Expired’}
}
}
}}

Leave a Reply

Your email address will not be published. Required fields are marked *