如何使用powershell脚本安装证书

Sha*_*did 4 powershell ssl ssl-certificate

我试图通过power-shell脚本安装证书.我正在使用Import-Certificatemicrosoft的power shell网站上的建议.这是我的代码

$script = {
    $file = ( Get-ChildItem -Path  C:\Users\Administrator\Desktop\newCert.cer )
    $file | Import-Certificate -CertStoreLocation cert:\CurrentUser\Root
    echo $file
    }

invoke-command -Credential $clientCred -ComputerName $ClientIP -ScriptBlock $script
Run Code Online (Sandbox Code Playgroud)

所以我得到以下错误.

UI is not allowed in this operation
    + CategoryInfo          : InvalidArgument: (:) [Import-Certificate], ArgumentException 
Run Code Online (Sandbox Code Playgroud)

不知道哪里出错了.如果有人能指出我正确的方向,那将会非常有帮助.

Cry*_*t32 10

这里的问题是,当您将证书安装到Cert:\CurrentUser\Root(当前用户帐户中的受信任的根CA)时,基础CryptoAPI将调用以下对话框:

在此输入图像描述

这就是错误消息提到UI的原因.由于您尝试在远程会话中安装证书,因此无法按下远程主机的交互式会话中的按钮.这就是禁止UI对话的原因.

您可以做的是将证书安装到本地计算机商店.也就是说,安装它Cert:\LocalMachine\Root.

请注意,在将根证书安装到本地计算机存储区时,它会自动传播到该计算机上的所有用户帐户.也就是说,可以为可能不会假设这种信任的用户建立无意识的信任.