Install Certificate with PowerShell on Remote Server

Install Certificate with PowerShell on Remote Server

Remotely install certificates

Es gibt Situation, in denen man mal eben schnell ein Zertifikat auf einem entfernten Server oder Workstation installieren muss. Sei es ein Public- oder Privat-Key.

Install Certificate with PowerShell on Remote Server

Für solchen Situation ist die Powershell gemacht worden. In diesem Beispiel liegen die Zertifikate auf einem Share im Netzwerk bereit. Diese können natürlich auch lokal auf den jeweiligen Maschinen liegen.

Beginnen wir mit dem Import eines fremden Zertifikats in den Speicher TrustedDevices.

Invoke-Command -ComputerName FI -ScriptBlock { Import-Certificate -FilePath “\\windowspapst.de\DFS\PUBLIC\Master.cer” -CertStoreLocation Cert:\LocalMachine\TrustedDevices }

Remotely install certificates

Dem fremden Zertifikat soll natürlich auch vertraut werden dürfen. Dafür importieren wir den Public-Key der Root-CA, des fremden Zertifikats in den Speicher Trusted Roots.

Invoke-Command -ComputerName FI -ScriptBlock { Import-Certificate -FilePath “\\windowspapst.de\DFS\PUBLIC\Master-RootCA.cer” -CertStoreLocation Cert:\LocalMachine\Root }

Install Certificate with PowerShell on Remote Server

Install PFX Certificate with PowerShell on Remote Server

PFX-Zertifikate als wieder exportierbar oder auch nicht, importieren wir mit diesem Invoke-Command Befehl.

Invoke-Command -ComputerName FI -ScriptBlock {
$plaintextPassword = “ndsjn”
$certFile = “\\windowspapst.de\DFS\PUBLIC\Master.pfx”
$location = “Cert:\LocalMachine\MY”
Import-PFXCertificate -FilePath $certFile -CertStoreLocation $location -Password (ConvertTo-SecureString -String $plaintextPassword -AsPlainText -Force) -Exportable }

Install PFX Certificate with PowerShell on Remote Server

Soll das importierte Zertifikat nicht mehr exportierbar sein, so lassen wir den Paramter -Exportable einfach weg.

Invoke-Command -ComputerName FI -ScriptBlock {
$plaintextPassword = “ndsjn”
$certFile = “\\windowspapst.de\DFS\PUBLIC\Master.pfx”
$location = “Cert:\LocalMachine\MY”
Import-PFXCertificate -FilePath $certFile -CertStoreLocation $location -Password (ConvertTo-SecureString -String $plaintextPassword -AsPlainText -Force)  }

Die jeweiligen Zertifikatsspeicher habe ich in diesem Artikel beschrieben.

Wofür sind die einzelnen Zertifikatsspeicher bzw. Container?