Skip to content

Instantly share code, notes, and snippets.

Last active November 19, 2023 02:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
PowerShell function to trust a certificate
function Trust-Certificate {
# Prompt the user to input the certificate's path
$certPath = Read-Host "Enter path to certificate"
# Create a new X.509 certificate object
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
try {
# Import the certificate from the specified path
# Create a new X.509 store for Trusted Root Certification Authorities on the Local Machine
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", "LocalMachine")
try {
# Open the store, add the certificate to the store, and close the store
finally {
Write-Host "Certificate imported successfully."
catch {
Write-Host "Error importing the certificate: $_"
# Uncomment the below if you wish to immediately call the function
# Trust-Certificate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment