Skip to content

Instantly share code, notes, and snippets.

@pmolchanov
Created July 6, 2016 17:06
Show Gist options
  • Save pmolchanov/3c8a75f54a2b986b867af78992ad8508 to your computer and use it in GitHub Desktop.
Save pmolchanov/3c8a75f54a2b986b867af78992ad8508 to your computer and use it in GitHub Desktop.
Import SSL Certificate
&{
# Select PFX file dialog
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Title = "Select SSL Certificate in PFX format"
$OpenFileDialog.Filter = "Personal Information Exchange (*.pfx)|*.pfx"
$OpenFileDialog.ShowDialog() | Out-Null
$PFXFile = $OpenFileDialog.FileName
# Get password dialog
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") | Out-Null
$Password = [Microsoft.VisualBasic.Interaction]::InputBox("Enter PFX Password", "Enter PFX Password", "", -1, -1);
# Import SSL Cert
$X509Certificate2 = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$X509Certificate2.Import($PFX, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeySet -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet)
$X509Store_WebHosting = New-Object System.Security.Cryptography.X509Certificates.X509Store -ArgumentList @("WebHosting",[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)
$X509Store_WebHosting.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$X509Store_WebHosting.Add($X509Certificate2)
$X509Store_WebHosting.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment