我想在远程服务器上安装使用makecert.exe创建的证书(X.509)。我无法使用psexec或类似的东西,但必须使用PowerShell。在远程服务器上使用PowerShell安装证书
- 服务器操作系统:Windows Server 2008 R2的
- 的PowerShell版本:4
问题:如何将远程服务器上安装PowerShell的证书。
我想在远程服务器上安装使用makecert.exe创建的证书(X.509)。我无法使用psexec或类似的东西,但必须使用PowerShell。在远程服务器上使用PowerShell安装证书
问题:如何将远程服务器上安装PowerShell的证书。
要导入,您可以使用Import-PfxCertificate
一个PFX文件,例如
Import-PfxCertificate -FilePath YOUR_PFX_FILE.pfx -Password (ConvertTo-SecureString -String "THE_PFX_PASSWORD" -AsPlainText -Force)
要在远程计算机上执行此操作,可以使用Invoke-Command -ComputerName
(并使用UNC路径PFX文件)。
情景:服务器A拥有SSL证书,服务器B想的SSL证书导入
定义两个变量(服务器B只):
$afMachineName = "SomeMachineNameOrIp"
$certSaveLocation = "c:\temp\Cert.CER"
能够在两台机器上的信任(服务器& ServerB):
Function enableRemotePS() {
Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts $afMachineName -Force
Restart-Service WinRM
}
保存c ertificate(服务器B只):
Function saveCert([string]$machineName,[string]$certSaveLocation) {
Invoke-Command -ComputerName $machineName -ArgumentList $certSaveLocation -ScriptBlock {
param($certSaveLocation)
$cert = dir Cert:\LocalMachine\Root | where {$_.Subject -eq "CN=YOURCERTNAME" };
$certBytes = $cert.Export("cert");
[system.IO.file]::WriteAllBytes($certSaveLocation, $certBytes);
}
Copy-Item -Path \\$machineName\c$\temp\CertAF.CER -Destination $certSaveLocation
}
导入证书(仅适用于服务器B)
Function importCert([string]$certSaveLocation) {
$CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certSaveLocation
$CertStoreScope = "LocalMachine"
$CertStoreName = "Root"
$CertStore = New-Object System.Security.Cryptography.X509Certificates.X509Store $CertStoreName, $CertStoreScope
# Import The Targeted Certificate Into The Specified Cert Store Name Of The Specified Cert Store Scope
$CertStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$CertStore.Add($CertToImport)
$CertStore.Close()
}
远程服务器上的OS和PSH版本是什么? – Richard
我已将信息添加到原始问题。 –
您是否在两台计算机上都启用了PowerShell远程处理功能,并且两台计算机都相互信任“? –