?
Solved

How to remove computer certificate from the local store

Posted on 2013-01-31
12
Medium Priority
?
6,242 Views
1 Endorsement
Last Modified: 2013-02-13
Hello,

we have by error enrolled 2 computer certificates of the same kind to all workstations within our company. They were both made from "Computer Certificate Template" and each one is named differently. My question is how can I delete from all workstations certificate created from "Template Y" without touching certificate from "Template X"?

thanks in advice
Capture.PNG
1
Comment
Question by:ZUNO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
12 Comments
 

Expert Comment

by:ndr-itsolutions
ID: 38840078
You could use Powershell to remove the certificates, have a look at the following article:

http://technet.microsoft.com/en-us/library/hh847855.aspx
0
 

Author Comment

by:ZUNO
ID: 38854857
Hi,

I have performed following operation "get-ChildItem cert:LocalMachine\My" but from this output I cannot distinguish which certificate is from desired template.

PS H:\> get-ChildItem cert:LocalMachine\My


    Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\My


Thumbprint                                Subject
----------                                -------
541542F127F98522C372A82004F76D3716BBE814
115443E2E2EC110D6032EA0C022B5343B770D678

Open in new window

I checked manually that Thumbprint 541542F127F98522C372A82004F76D3716BBE814 corresponds to certificate I want to delete but it differs on every single PC.

Is there any way how can I filter out certificate only from my desired template? Otherwise this command will be useless for me as I need to run a start-up script for automatic deletion specified certificate from all PCs.
0
 
LVL 25

Expert Comment

by:Coralon
ID: 38866733
Normally, you should be able to just differentiate them by the expiration date.  In your screenshot, they clearly have different ones.  

If you are not sure, then your best bet is to just delete them both and then install the one you want on *one* machine.  That will tell you the expiration date, and then you will know which one to delete off of the other machines.

Coralon
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:ZUNO
ID: 38867306
Hi Coralon,

thanks for your reply but unfortunately this in not possible as we are using DOT1x and those certificates are used to authenticate computer in our network. This means if non of them will be found you are not authorised to access corporate network.
0
 
LVL 40

Expert Comment

by:footech
ID: 38868890
get-ChildItem cert:LocalMachine\My | Select *

Open in new window

Running the above will show you all the properties that you have access to.  I have no first hand experience with it myself, but from my knowledge the only practical way to manage local certificates with PowerShell is to use the Quest cmdlets.

It's easy enough to revoke all the certificates that have been issued from a particular template through the MMC on the CA, but this won't actually delete the certs.
0
 
LVL 25

Expert Comment

by:Coralon
ID: 38870351
That's why I was saying to try it on one machine.  Since you do require it in order to access your network, then it's still entirely possible.

Take that 1 machine, change the local admin password, or add a local admin account.  Remove both certs.  Then add the oldest one back and see if you can login to the network.  If that doesn't work, swap them out, and you should be good to go.  You'll be able to use the local account in order to login to swap out the certs.

Coralon
0
 

Author Comment

by:ZUNO
ID: 38879378
Hi footech, I have tried your command and now I see all the info I need. Currently I would need some script/command that will do the following  
"delete cert from cert:LocalMachine\My where SerialNumber = 123456"  

Is there anything like this? Or

"delete cert from cert:LocalMachine\My where TemplatName = TemplateX"


Coralon for some unknown reason I'm not able to delete those certs - still getting an error. I have tested it with local user account on test computer, with Local admin account on test computer, with Enterprise admin account on another computer and those certs are still there :-/

I have never worked with PowerShell so what am I doing wrong?

PS C:\> get-childitem cert:\LocalMachine\My


    Directory: Microsoft.PowerShell.Security\Certificate::LocalMachine\My


Thumbprint                                Subject
----------                                -------
541542F127F98522C372A82004F76D3716BBE814
115443E2E2EC110D6032EA0C022B5343B770D678


PS C:\> remove-item cert:\LocalMachine\My\

Confirm
The item at cert:\LocalMachine\My\ has children and the Recurse parameter was not specified. If you continue, all
children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
Remove-Item : Provider execution stopped because the provider does not support this operation.
At line:1 char:12
+ remove-item <<<<  cert:\LocalMachine\My\
    + CategoryInfo          : NotImplemented: (:) [Remove-Item], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.RemoveItemCommand

PS C:\>




PS C:\> PS C:\>get-childitem cert:\LocalMachine\My\541542F127F98522C372A82004F76D3716BBE814
Get-Process : A positional parameter cannot be found that accepts argument 'cert:\LocalMachine\My\541542F127F98522C372A
82004F76D3716BBE814'.
At line:1 char:3
+ PS <<<<  C:\>get-childitem cert:\LocalMachine\My\541542F127F98522C372A82004F76D3716BBE814
    + CategoryInfo          : InvalidArgument: (:) [Get-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand

PS C:\>

Open in new window

0
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 38882045
PS 2.0 doesn't really support removing certs with built-in cmdlets (see http://technet.microsoft.com/en-us/library/hh847807.aspx ), though I have found a work-around.
Since "serialnumber" is actually a property that we have access to, we could match against that, but no certificate should have the same serial number, so I don't see it being much use in the long run.  There is no attribute for Template name and I don't know how the snap-in determines this.  I did some digging and there is some related info in a certificate's extensions, but running a command like the following - I don't see a match between any of the values (which looks like an OID) and numbers I could see in the templates.  It appears that the OID actually matches with the template version.
gci cert:\LocalMachine\My | % {$_.extensions} | % {$_.oid | ? {$_.FriendlyName -like "Certificate Template*" }}

Open in new window

Here's some PS code you can use to remove a certificate, but I'm still not sure what criteria you would use to filter the list.  I'm kind of thinking expiration (or start) date might be best, but that depends on your environment (if there was a clear separation between certificates issued with one template vs. another).
$store = New-Object System.Security.Cryptography.x509Certificates.x509Store("My","LocalMachine")
$store.Open("ReadWrite")
# Need some criteria here to filter the list of certificates appropriately
$certs = $store.Certificates | Where {$_.NotBefore -lt "7/20/2012"}
ForEach ($cert in $certs)
{
  $store.Remove($cert)
}
$store.Close()

Open in new window

0
 
LVL 25

Expert Comment

by:Coralon
ID: 38883036
You couldn't delete it with the local admin?  That seems really odd.. I'm talking about doing this graphically with the certificates MMC. If it was still locked, I'd remove the network cable, reboot it, and try again from the console of the machine.

Coralon
0
 

Author Comment

by:ZUNO
ID: 38884876
Hi footech,

your script works like a charm :) I just changed one parameter to met my expiration date.

{$_.NotBefore -lt "7/20/2012"} => {$_.NotAfter -gt "1/1/2015"}

thanks for your help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question