Mittwoch, 6. November 2013

Import Certificate with PowerShell

Import Certificate in windows cert store using Powershell and X509Certificate2 class.

if (-not (dir cert:\currentuser\My | Where-Object {$_.Thumbprint -eq "5649d14b2abbafa50123456"})) {
    $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
    $cert.Import("c:\certs\Certificate.pfx","PlainTextPassword",[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"UserKeySet")
    $store = New-Object System.Security.Cryptography.X509Certificates.X509Store "My", "CurrentUser"
    $store.Open("ReadWrite")
    $store.Add($cert)
    $store.Close()
}

The original script has been copied from:
http://social.technet.microsoft.com/Forums/windowsserver/en-US/28bd6ad1-0627-420c-b995-1ab420710b54/automating-ca-certificate-installtion?forum=winserversecurity

Keine Kommentare:

Kommentar veröffentlichen