I am trying to check for, and then remove a certificate if it exists in a user's local machine store. I've tried this:
$certCN = 'test.domain.com'
Set-Location Cert:\LocalMachine\My
$oldCert = Get-ChildItem -Recurse |
Where-Object { $_.subject -like "CN=$oldCert*" }
Remove-Item Cert:\LocalMachine\My\$oldCert -Force
But it is not removing the cert from the store or giving any errors (yes I am running this elevated).
I checked my $oldCert variable to see if it is populated and it is:
PS Cert:\LocalMachine\My> $oldcert
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My
Thumbprint Subject
---------- -------
276B7B87740D5E9595A258060F5CD9CC4190E9E1 CN=test.domain.com, <truncated>
Does anyone know how to accomplish this? I really appreciate it.