使用powershell在远程服务器上安装pfx证书

使用powershell在远程服务器上安装pfx证书,powershell,certificate,installation,pfx,Powershell,Certificate,Installation,Pfx,按照这个,, 我正在尝试使用以下Powershell命令在远程服务器上安装pfx证书 Invoke-command -ComputerName myservername -scriptblock { Import-PfxCertificate –FilePath D:\pfxcert.pfx cert:\localMachine\my -Password (ConvertTo-SecureString -String "mypassword" -Force –AsPlainText) } 这

按照这个,,

我正在尝试使用以下Powershell命令在远程服务器上安装pfx证书

Invoke-command -ComputerName myservername -scriptblock { Import-PfxCertificate –FilePath D:\pfxcert.pfx cert:\localMachine\my -Password (ConvertTo-SecureString -String "mypassword" -Force –AsPlainText) }
这是给我下面的错误信息

The term 'Import-PfxCertificate' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo          : ObjectNotFound: (Import-PfxCertificate:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName        : myservername

请在这方面帮助我。

目标计算机上不存在
Import-PfxCertificate
cmdlet。可能是因为它运行的Powershell版本少于3


如果可能,您必须安装更新版本的PowerShell,或者找到导入证书的其他方法。

好吧,如果您需要从C#调用它,那么可能值得从C#安装它,如


实际上,它与powershell中的代码大致相同,因为除了使用.net系统类或类似工具之外,没有其他方法。

Cmdlet
Import-PfxCertificate
是模块
PKIClient
的一部分

Windows PowerShell中的PKI客户端cmdlet仅在上可用

  • Windows 8.1
  • Windows PowerShell 4.0
  • Windows Server 2012 R2
尝试在脚本中加载PKI客户端:

Invoke-command -ComputerName myservername -scriptblock 
{ 
    Get-Command -Module PKIClient; 
    Import-PfxCertificate –FilePath D:\pfxcert.pfx cert:\localMachine\my -Password (ConvertTo-SecureString -String "mypassword" -Force –AsPlainText) 
}

您可以尝试
Get Command-Module PKIClient
查看所有cmdlet。

感谢您的快速响应,您能否分享一些如何以其他方式实现此目的的示例?我必须用c#代码调用这个powershell脚本。StackOverflow实际上不是这样工作的。你需要自己研究其他方法。如果你被卡住了,回来再问一个问题,说在哪里。该网站不是一个代码编写服务,它不太可能有人会为您编写整个脚本!似乎至少应该是Windows 8.1/Windows Server 2012 R2(请参阅),即仅使用更新版本的PowerShell(如4.0或5.0)是不够的。
Invoke-command -ComputerName myservername -scriptblock 
{ 
    Get-Command -Module PKIClient; 
    Import-PfxCertificate –FilePath D:\pfxcert.pfx cert:\localMachine\my -Password (ConvertTo-SecureString -String "mypassword" -Force –AsPlainText) 
}