How to import an SSL certificate file into the local machine's root certificate store.

# To import an SSL certificate file into the local machine's root certificate store:
Import-Certificate -FilePath C:\path\to\certificate.crt -CertStoreLocation Cert:\LocalMachine\Root

#
# Working Example (NOTE: Requires Windows 8+, Windows Server 2012+)
# ----------------------------------------------------------------------------

function Write-Info
{
    param([string] $message)

    Write-Host "$message" -ForegroundColor Cyan
}

function Write-Success
{
    param([string] $message)

    Write-Host "$message" -ForegroundColor Green
}

function Write-Err
{
    param([string] $message)

    Write-Error "$message" -ForegroundColor Red
}

function Import-Intermediate-Cert
{
    param([string] $certpath)

    $fileBaseName = [System.IO.Path]::GetFileName($certpath)

    Write-Info "> Importing '$fileBaseName' into 'LocalMachine' 'Intermediate Certification Authorities' Store"

    Import-Certificate -FilePath "$certpath" -CertStoreLocation Cert:\LocalMachine\CA

    Write-Host "Done."
    Write-Host
}

function Import-Root-Cert
{
    param([string] $certpath)

    $fileBaseName = [System.IO.Path]::GetFileName($certpath)

    Write-Info "> Importing '$fileBaseName' into 'LocalMachine' 'Trusted Root Certification Authorities' Store"

    Import-Certificate -FilePath "$certpath" -CertStoreLocation Cert:\LocalMachine\Root

    Write-Host "Done."
    Write-Host
}

function Main
{
    $baseDir = Split-Path $script:MyInvocation.MyCommand.Path

    # Import DEV Chain
    Import-Intermediate-Cert "$baseDir\certs\dev\Dev_Issuing.cer"
    Import-Root-Cert "$baseDir\certs\dev\Dev_Root.cer"

    #Import QA Chain
    Import-Intermediate-Cert "$baseDir\certs\qa\Qa_Issuing.cer"
    Import-Root-Cert "$baseDir\certs\qa\Qa_Root.cer"

    if ($? -eq $true)
    {
        Write-Success "Finished."
    }
    else
    {
        Write-Err "Finished (with errors)."
    }
}

Main