Import Certificate

1. On Windows 10

Since Windows 8 and Windows Server 2012, importing certificates can be done easily using PowerShell, and more precisely with the command Import-Certificate

This cmdlet allows to import one or more certificates in to a certificate store.

In case of PFX certificate, the command Import-PfxCertificate can be used (Imports certificates and private keys from a Personal Information Exchange (PFX) file to the destination store).

## Import the Certificate MyCert.cer in the Intermediate Certification Authorities
Write-Host "----- Import the Certificate MyCert.cer in the Intermediate Certification Authorities -----"
Try {
Import-Certificate -FilePath "C:\Certificates\MyCert.cer" -CertStoreLocation Cert:\LocalMachine\CA
Write-Host "Certificate imported successfully "
} 
Catch {
Write-Host "Exception caught in importing certificate : $error[0]"
Exit-Script -ExitCode 3 
}

.

.

2. On Windows 7

For Windows 7, there is no PowerShell command to import certificates, but the tool certmgr can be used.

Here is a script allowing to import a certificate using certmgr:

## Import the Certificate MyCert.cer in the Intermediate Certification Authorities
Write-Host "----- Import the Certificate MyCert.cer in the Intermediate Certification Authorities -----"
Try {
Execute-Process -Path 'C:\Certificates\certmgr.exe' -Parameters "-add –all C:\Certificates\MyCert.cer -s -r localmachine CA" 
Write-Host "Certificate imported successfully "
} 
Catch {
Write-Host "Exception caught in importing certificate : $error[0]"
Exit-Script -ExitCode 3 
}