如何使用 PowerShell 将证书安装到证书存储区?

powershellmicrosoft technologiessoftware & coding

要使用 PowerShell 安装证书,我们需要使用 Import-Certificate 命令。例如,我们有一个证书存储在 C:\temp\Mycert.cer 位置,我们需要将其安装到本地计算机的个人证书存储区。

示例

Import-Certificate -FilePath C:\Temp\Mycert.cer `
   -CertStoreLocation Cert:\LocalMachine\My\

您也可以使用以下方法。

PS C:\> Set-Location Cert:\LocalMachine\My\
PS Cert:\LocalMachine\My\> Import-Certificate -FilePath C:\Temp\Mycert.cer

要在远程计算机上安装证书,请使用Invoke-Command方法。

语法

Invoke-Command -ComputerName  RemoteServer1 -ScriptBlock {Import-Certificate -FilePath C:\Temp\Mycert.cer `
   -CertStoreLocation Cert:\LocalMachine\My\ }

上述命令会将证书从远程服务器 C:\temp 的路径安装到远程服务器 RemoteServer1 的个人证书存储区。


相关文章