Skip to content

Instantly share code, notes, and snippets.

@asheroto
Created October 11, 2023 05:47
Show Gist options
  • Save asheroto/d08cbea420d678493ec8fa0dd42514cb to your computer and use it in GitHub Desktop.
Save asheroto/d08cbea420d678493ec8fa0dd42514cb to your computer and use it in GitHub Desktop.
Import PFX files with PowerShell using the .NET class.
# Load the PFX file into an X509Certificate2 object
$pfxPath = "path_to_your.pfx"
$password = "your_password" # Consider using SecureString for production use
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
# Import the PFX into the certificate object
$cert.Import($pfxPath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet)
# Add the certificate to the desired store (in this case, the Personal store of the CurrentUser)
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "My", "CurrentUser"
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($cert)
$store.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment