Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell script that imports a .pfx certificate file. Useful to do before building the solution on a build server.
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]"PersistKeySet")
$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::"ReadWrite")
$store.Add($cert)
$store.Close()
@liushuanggang

This comment has been minimized.

Copy link

commented Aug 23, 2019

@deadlydog, What the value should be set for "MY"?

@deadlydog

This comment has been minimized.

Copy link
Owner Author

commented Aug 23, 2019

@deadlydog, What the value should be set for "MY"?

MY is the correct value. See the docs for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.