title: Removing a certificate from the local machine certificate store in powershell?
body: <p>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:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$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
  </code></pre>
  
  <p>But it is not removing the cert from the store or giving any errors (yes I am running this elevated).</p>
  
  <p>I checked my <code>$oldCert</code> variable to see if it is populated and it is:</p>
  
  <pre><code>PS Cert:\LocalMachine\My&gt; $oldcert
  PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My
  
  Thumbprint                                Subject                                                                                                                                                                       
  ----------                                -------                                                                                                                                                                       
  276B7B87740D5E9595A258060F5CD9CC4190E9E1  CN=test.domain.com, &lt;truncated&gt;
  </code></pre>
  
  <p>Does anyone know how to accomplish this?  I really appreciate it.</p>