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!
I use
CertMgr.exe
and a simple bat file to import certs.Here is a TechNet article which documents what commands/usage you can do with certmgr.exe
I haven't found a script to import it into the certificate into the correct store based on it's template. I think you have made that script yourself because It simply doesn't exist. What I did found is a PowerShell script which import certificates from a directory and in the command you have to specify the correct store yourself. I thought It might be useful for you:
How to use the script Function to import security certificates.
NOTE: To get a list of available store names, run the following command: dir cert: | Select -Expand StoreNames
Example Usages: Import-Certificate -CertFile "VeriSign_Expires-2028.08.01.cer" -StoreNames AuthRoot, Root -LocalMachine
Import-Certificate -CertFile "VeriSign_Expires-2018.05.18.p12" -StoreNames AuthRoot -LocalMachine -CurrentUser -CertPassword Password -Verbose
dir -Path C:\Certs -Filter *.cer | Import-Certificate -CertFile $_ -StoreNames AuthRoot, Root -LocalMachine -Verbose
Script itself:
Source: Import-Certificate