Created
July 8, 2013 18:12
-
-
Save opentable-devops/5951108 to your computer and use it in GitHub Desktop.
Script that will allow you to import a certificate for use on Windows Server 2008 and upwards.
This file contains 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
.\import-certificate.ps1 -CertificateName "" -CertLocation "" | |
param( | |
[Parameter( | |
Mandatory=$true, | |
HelpMessage="Name of the cert - this will copy the certificate from tron to the local machine")] | |
[string]$CertificateName, | |
[Parameter( | |
Mandatory=$true, | |
HelpMessage="The location of the certificate. This currently cannot be a remote location as the script would need to map drives to access it")] | |
[string]$CertLocaton, | |
[Parameter( | |
Mandatory=$false, | |
HelpMessage="Root store for the certificate (default is LocalMachine)")] | |
[string]$CertRootStore = "LocalMachine", | |
[Parameter( | |
Mandatory=$false, | |
HelpMessage="The directory to store the certificate (default is My)")] | |
[string]$CertStoreDirectory = "My", | |
[Parameter( | |
Mandatory=$false, | |
HelpMessage="The password for the certificate")] | |
[string]$CertPassword | |
) | |
function Import-PfxCertificate($certName, $CertLocaton, $certRootStore, $certStore, $certPath) { | |
$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 | |
$pfxPass = convertto-securestring $CertPassword -asplaintext -force | |
$certPath = $CertLocaton + "\" + $certName | |
$pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") | |
$store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) | |
$store.open("MaxAllowed") | |
$store.add($pfx) | |
$store.close() | |
} | |
Write-Host('Starting Certificate Import') | |
Import-PfxCertificate $CertificateName $CertLocaton $certRootStore $CertStoreDirectory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment