Link to home
Start Free TrialLog in
Avatar of vodyanoi
vodyanoi

asked on

powershell script for SSL expiry

Hello,

we have taken the script from this website

http://gallery.technet.microsoft.com/scriptcenter/a4760914-cf72-4505-97d3-94166c7d3521

and modified it to return only those certificates expiring within the next 30 days.

Original script:
get-childitem cert: -recurse | where-object {$_.NotAfter -gt (get-date)} | select Subject,@{Name="Expires in (Days)";Expression={($_.NotAfter).subtract([DateTime]::Now).days}} | Sort "Expires in (Days)"

Modified script: - change in bold
get-childitem cert: -recurse | where-object {$_.NotAfter -lt (get-date).adddays(30) }| select Subject,@{Name="Expires in (Days)";Expression={($_.NotAfter).subtract([DateTime]::Now).days}} | Sort "Expires in (Days)"


this has the unfortunate consequence of displaying the SSL certificates that have already expired, which we are not interested in as they are system installed certificates.

What we are hoping is to modify the expression to return only the certificates expiring in the future.  We assume this would need to return results between todays date and 30 days in the future but we cannot work out how to do this.

does anyone have a suggestion on how to resolve this?



Kind regards


Spencer
ASKER CERTIFIED SOLUTION
Avatar of Member_2_3654191
Member_2_3654191
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vodyanoi
vodyanoi

ASKER

Excellent,

Having tested this I can confirm this does exactly what we need.

I can see now how to include the and logical operator.  When we tried we placed the enclosing brackets in the wrong locations.

Many thanks for this


Spencer
Any chance either of would know how to exclude self signed certs via this powershell command?