Remove Expired Certs in LocalMachine\My remotely using Powershell

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Mark Mark 1 year ago.

  • Author
  • #30439
    Profile photo of ATG

    Any help will be appreciated.
    I have hundred of servers with Certs in the LocalMachine\My Store.
    I can see the Cert opening a Session and Running Get-ChildItem cert:\Localmachine\my.
    Is their a way that I removed only the Cert that are expired using a powershell script?
    I have a list of servers in a text file.

    I have tried this with no success:

    $today = Get-Date
    $session = New-PsSession –ComputerName TestServer
    Invoke-Command -ComputerName $session { Get-ChildItem -Path Cert:\LocalMachine\My } | foreach { If ( $_.NotAfter -lt $today) { $_.Remove($Cert) }


  • #30454
    Profile photo of Mark

    Your are attempting to use .remove on the certificate object.

    .Remove needs to be used on the cert store object, such as (cert:\LocalMachine\my).Remove($Cert)

You must be logged in to reply to this topic.