Skip to content

Instantly share code, notes, and snippets.

@wafe
Forked from deadlydog/Import-PfxCertificate.ps1
Last active April 28, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wafe/c7a14f63fa13a2a7c9eed7d9db506446 to your computer and use it in GitHub Desktop.
Save wafe/c7a14f63fa13a2a7c9eed7d9db506446 to your computer and use it in GitHub Desktop.
PowerShell script that imports a .pfx certificate file. To install pfx certificate on IIS
param($PfxFilePath, $Password)
$absolutePfxFilePath = Resolve-Path -Path $PfxFilePath
Write-Output "Importing store certificate '$absolutePfxFilePath'..."
Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($absolutePfxFilePath, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags] "MachineKeySet, PersistKeySet")
$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", LocalMachine
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::"ReadWrite")
$store.Add($cert)
$store.Close()
@coreyperkins
Copy link

What the hell is this?

System.Security.Cryptography.CryptographicException: Keyset does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment