title: Remove Expired Certificates with Powershell
body: <p>I have a simple script to show all certificates on a server, I would like to expand that script to then remove all expired certificates</p>
  
  <p>I have tried several scripts from MS and 3rd parties to find a remove certs but have had no luck with them working properly</p>
  
  <p>The first code I am using is:</p>
  
  <p><strong>Get-ChildItem Cert:\ -Recurse</strong></p>
  
  <p>This Powershell script shows all certificates on a server. </p>
  
  <p>Example output is below for each certificate. I want to target the NotAfter field and have the script then remove the certificate if it's old than todays date</p>
  
  <p>Subject:
  Issuer:
  Thumbprint:
  FriendlyName:
  NotBefore:
  NotAfter:
  Extensions</p>
  
  <p>I would also like to do this for a list of servers, have the script run on each server in a text document, query all certificates, then remove the certs that are expired and move on to the next server.</p>
  
  <p>I have seen some code targeting the date like the following:</p>
  
  <p><strong>ForEach-Object -begin { $now = get-date } -process { if ($PSItem.NotAfter -lt $now ) { $PSItem } } | Remove-Item</strong></p>
  
  <p>I would like the script to go out and query a servers certificates, then deletes out the expired certificates</p>