我们导入Windows服务证书一般使用双击方式按照向导导入和MMC导入,今天我们介绍通过Powershell导入PFX证书,具体见下:

  • 将PFX证书导入本地计算机的的个人证书中
$Pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
Import-PfxCertificate -FilePath "d:\mycert.pfx" -CertStoreLocation Cert:\LocalMachine\My -Password $Pwd
  • 将PFX证书导入本地计算机的的受信任颁发机构中
$Pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
Import-PfxCertificate -FilePath "d:\mycert.pfx" -CertStoreLocation Cert:\LocalMachine\Root -Password $Pwd
  • 将PFX证书导入当前用户个人证书中
$Pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
Import-PfxCertificate -FilePath "d:\mycert.pfx" -CertStoreLocation Cert:\CurrentUser\My -Password $Pwd
  • 将PFX证书导入当前用户的受信任颁发机构中
$Pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
Import-PfxCertificate -FilePath "d:\mycert.pfx" -CertStoreLocation Cert:\CurrentUser\Root -Password $Pwd
  • 或者也可以下面这样写
Import-PfxCertificate -FilePath "d:\mycert.pfx" -CertStoreLocation Cert:\CurrentUser\Root -Password $(ConvertTo-SecureString -String "123456" -AsPlainText -Force)