Public/Install-RootCert.ps1

#Requires -Modules PKI
#Requires -RunAsAdministrator

function Install-RootCert {
    
        param(
            [ValidateScript( {Test-Path $_})]
            [string]$Path
        )
    
    
        $rootCrtInfo = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
        $rootCrtInfo.Import($Path)
        $rootCrtThumbprint = $rootCrtInfo.Thumbprint
    
        # install root cert
        $rootCerts = Get-ChildItem -Path Cert:\ -Recurse | Where-Object {
            $_.PSIsContainer -eq $false -and $_.Thumbprint -eq $rootCrtThumbprint 
        }
        $rootCertInstalled = $false
        if ($rootcerts) {
            $rootCerts | Select-Object -Property PSParentPath, Subject, Thumbprint, HasPrivateKey
            $rootCert = $rootCerts | Where-Object { $_.PSParentPath -like '*LocalMachine\Root' }
            if ($rootCert) {
                $rootCertInstalled = $true
            }
        }
    
        if (!$rootCertInstalled) {
            Write-Host "Installing Root Certificate"
            Import-Certificate -FilePath $Path -CertStoreLocation Cert:\LocalMachine\Root
        }
        else {
            Write-Host "Certificate already installed '$Path'"
        }
    
    }