Created
October 11, 2023 05:47
-
-
Save asheroto/d08cbea420d678493ec8fa0dd42514cb to your computer and use it in GitHub Desktop.
Import PFX files with PowerShell using the .NET class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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