Import a Root and Intermediate cert into your local stores using PowerShell

CheckHere is a handy and straight forward PowerShell function to import a Root and Intermediate cert into your local stores using PowerShell.

#Begin Script ~~
function Import-Certificate {
Param ([String]$certFileIn, `
[String]$certRootStoreIn = “LocalMachine”, `
[string]$certStoreIn)

$certFile = Get-ChildItem $certFileIn $cert = New-Object
System.Security.Cryptography.X509Certificates.X509Certificate2($certFile.FullName)
$store = get-item Cert:\$certRootStoreIn\$certStoreIn
$store.Open(“ReadWrite”)
$store.Add($cert)
$store.Close()
}

# Root Certificate
Import-Certificate “C:\CertFolder\CertRoot.cer” “LocalMachine” “Root”

# Intermediate Certificate
Import-Certificate “C:\CertFolder\CertInterm.cer” “LocalMachine” “CA”

#End of Script ~~