Created
August 18, 2020 06:32
-
-
Save techdecline/af31b8a41b40c1a25e9fb93308552bf6 to your computer and use it in GitHub Desktop.
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
| param ( | |
| [Parameter(Mandatory)] | |
| [String]$Pkcs12String, | |
| [Parameter(Mandatory=$false)] | |
| [ValidateSet("CurrentUser","LocalMachine")] | |
| [String]$CertificateStoreLocation = "LocalMachine", | |
| [Parameter(Mandatory=$false)] | |
| [String]$CertificateStoreName = "My" | |
| ) | |
| # Write Certificate to temporary file | |
| $certFile = New-TemporaryFile | |
| $Pkcs12String | Out-File $certFile.FullName | |
| # Create certificate object | |
| $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 | |
| # Import certificate file into certificate object | |
| $pfx.Import($certFile.FullName, $null, "Exportable,PersistKeySet") | |
| # Add certificate to selected store | |
| $store = new-object System.Security.Cryptography.X509Certificates.X509Store($CertificateStoreName,$CertificateStoreLocation) | |
| $store.open("MaxAllowed") | |
| $store.add($pfx) | |
| $store.close() | |
| # Cleanup temporary file | |
| Remove-Item $certFile | |
| return $pfx.Thumbprint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment