Windows – Import a bunch of certificates into the correct certificate store using a script

certificatesslwindows

I have a collection of certificates in a p7b file, and I would like to automatically import each certificate into the correct store depending on the certificate template. What is the best way to do this with a script?

I tried using certutil -addstore root Certificate.p7b, and that will correctly place all of the root CAs into the root store, but it returns an error if it encounters any other type of certificate.

I'm willing to use batch scripts, vbscript or powershell to accomplish this task. Thanks!

Best Answer

I use CertMgr.exe and a simple bat file to import certs.

certmgr.exe -add -c ca.cer -s -r localMachine root  >> log.txt
certmgr.exe -add -c test.cer -s -r localMachine root  >> log.txt
certmgr.exe -add -c edu.cer -s -r localMachine root  >> log.txt

Here is a TechNet article which documents what commands/usage you can do with certmgr.exe