We are cleaning up our server environment and need to find all expired certs and delete them. The environment consists of Windows 2008 R2, Windows 2012, Windows 2012 R2 servers
I have tried several published scripts that don't work, they just say completed with no output. I tried one published in stackoverflow: Powershell Script to remove expired certificates. I have also tried a few of the scripts below as well with no luck. Using the one by thumbprint is ok but I need to get rid of all expired certs
'''
Delete by thumbprint
Get-ChildItem Cert:\LocalMachine\My\D20159B7772E33A6A33E436C938C6FE764367396 | Remove-Item
Delete by subject/serialnumber/issuer/whatever
Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -match 'Frode F' } | Remove-Item ''' ''' $today = Get-Date Get-ChildItem Cert:\CurrentUser\My | Where-Object NotAfter -lt $today | Remove-Item
or
Get-ChildItem Cert:\CurrentUser\My | ForEach-Object -begin { $now = get-date } -process { if ($PSItem.NotAfter -lt $now ) { $PSItem } } | Remove-Item '''
What I'm trying to achieve is removing ALL expired certificates on all servers in a list leveraging a foreach statement that references a list of servers in a text file, then goes out and removes all certificates expired from yesterdays date and older
Anything you guys can think of would be of great help to me
Any help is greatly appreciated