Changing color of certificates which will expire in next 90 days from the complete list

Viewed 24

I am working on a script which gets me output from Hyper-v cluster nodes + some VMs. I have the below code which gives me list of all the available certificates and the days remaining for the certificate to expire. I am using PowerShell version: 5.1 and PowerShell ISE for this:

import-module hyper-v
import-module failoverclusters
#Add infra infra VM's:
$machines = @()
$allinfravms = (Get-VM -CimSession (Get-ClusterNode -Cluster MyCluster).Name | ? { $_.Notes.Length -eq 0 }).name
$machines += $allinfravms 

# Add physical nodes to check:
$allnodes = (Get-ClusterNode -cluster MyCluster).name
$machines += $allnodes

#Run command on all the nodes:
Invoke-Command $machines {Get-ChildItem -Path Cert:\LocalMachine\My } | select PSComputername,Thumbprint,Subject,@{n=’ExpireInDays’;e={($_.notafter – (Get-Date)).Days}} -OutVariable Expiringcerts | out-null

I am looking forward for a way to output all the certificates but the certificates that will be expiring in next 90 days should be in red color (Line) in the list.

0 Answers
Related