# Remove Expired Certs in LocalMachine\\My remotely using Powershell

**URL:** <https://forums.powershell.org/t/remove-expired-certs-in-localmachine-my-remotely-using-powershell/4974>\
**Category:** Website & Forum Feedback\
**Created:** [October 5, 2015, 7:07am UTC](https://forums.powershell.org/t/remove-expired-certs-in-localmachine-my-remotely-using-powershell/4974 "2015-10-05T07:07:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![armando-torres](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@armando-torres](https://forums.powershell.org/u/armando-torres)\
**Post date:** [October 5, 2015, 7:07am UTC](https://forums.powershell.org/t/remove-expired-certs-in-localmachine-my-remotely-using-powershell/4974/1 "2015-10-05T07:07:08Z")

</div>

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) }  
}

Thanks!

---

<div class="post-metadata">

**Author:** ![mark-stone](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@mark-stone](https://forums.powershell.org/u/mark-stone)\
**Post date:** [October 5, 2015, 11:31pm UTC](https://forums.powershell.org/t/remove-expired-certs-in-localmachine-my-remotely-using-powershell/4974/2 "2015-10-05T23:31:00Z")

</div>

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)
