| 185 |
rodolico |
1 |
# Ensure this script runs as an administrator
|
|
|
2 |
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
|
3 |
throw "Run this script as Administrator!"
|
|
|
4 |
}
|
|
|
5 |
|
|
|
6 |
# change this to the actual name of your Certificate
|
|
|
7 |
$PemFileName = "ca.pem"
|
|
|
8 |
|
|
|
9 |
# Define the path to the PEM file
|
|
|
10 |
$CurrentDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
|
11 |
$PemFilePath = Join-Path -Path $CurrentDir -ChildPath $PemFileName
|
|
|
12 |
|
|
|
13 |
# Check if PEM file exists
|
|
|
14 |
if (-Not (Test-Path $PemFilePath)) {
|
|
|
15 |
throw "CA PEM file not found at path: $PemFilePath"
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
# Import CA from PEM file using certutil
|
|
|
19 |
Write-Host "Importing the Certificate Authority from PEM file..." -ForegroundColor Cyan
|
|
|
20 |
|
|
|
21 |
certutil -addstore -f "ROOT" $PemFilePath
|
|
|
22 |
|
|
|
23 |
# Verify that the CA was imported successfully
|
|
|
24 |
$importedCA = Get-ChildItem Cert:\LocalMachine\Root | Where-Object { $_.Subject -like "*CN=*" }
|
|
|
25 |
if ($importedCA) {
|
|
|
26 |
Write-Host "Successfully imported CA from PEM file:" -ForegroundColor Green
|
|
|
27 |
$importedCA | Format-Table -Property Subject, Thumbprint
|
|
|
28 |
} else {
|
|
|
29 |
Write-Host "Failed to import CA from PEM file." -ForegroundColor Red
|
|
|
30 |
}
|