Subversion Repositories sysadmin_scripts

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
188 rodolico 1
# Script will download a CA .crt file from a URL, then install the CA
2
# into the Trusted Root Certificates Authorities store
3
# Must be run as administrator
4
# change $crtPath and $crtUrl for your specific installation
5
#
6
# will create c:\Temp if it doesn't exist
7
 
8
# Set the URL for the CA .crt file
9
$crtUrl = "http://example.org/myCA.crt"  # Replace this with your actual URL
10
 
11
# Set the path where you want to save the certificate
12
$crtPath = "C:\Temp\myCA.crt"
13
 
14
# Ensure this script runs as an administrator
15
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
16
    throw "Run this script as Administrator!"
17
}
18
 
19
# Create the Temp directory if it doesn't exist
20
If (!(Test-Path "C:\Temp")) {
21
    New-Item -ItemType Directory -Path "C:\Temp"
22
}
23
 
24
# Download the CA certificate
25
Invoke-WebRequest -Uri $crtUrl -OutFile $crtPath
26
 
27
# Check if the download was successful
28
If (Test-Path $crtPath) {
29
    Write-Host "Downloaded certificate to $crtPath"
30
 
31
    # Install the certificate to the Trusted Root Certification Authorities store
32
    $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
33
    $cert.Import($crtPath)
34
 
35
    $store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", "LocalMachine")
36
    $store.Open("ReadWrite")
37
    $store.Add($cert)
38
    $store.Close()
39
 
40
    Write-Host "CA certificate installed successfully."
41
} else {
42
    Write-Host "Failed to download the certificate."
43
}