Certificate Install Script for Microsoft Windows

This script is designed to automate the installation of a digital certificate into the "Trusted Root Certification Authorities" store on a local machine. It can be distributed and executed via Remote Monitoring and Management (RMM) tools, making it ideal for deploying trusted certificates across multiple systems in a managed environment.
 

# Path to the certificate file
$certPath = "C:\Users\username\Downloads\DESKTOP_CERTIFICATE.der"# Check if the file exists
if (Test-Path $certPath) {
# Import the certificate into the Trusted Root Certification Authorities store
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($certPath) # Add the certificate to the local machine Trusted Root store
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root", "LocalMachine"
$store.Open("ReadWrite")
$store.Add($cert)
$store.Close() Write-Host "Certificate installed successfully."
} else {
Write-Host "Certificate file not found at $certPath. Exiting."
}        

Related to

Updated

Was this article helpful?

0 out of 1 found this helpful

Have more questions? Submit a request

Comments

1 comment

  • Comment author
    Brandon Fox

    Where do I get the certificate from? I would expect the script to download it, but it doesn't. 

    0

Please sign in to leave a comment.