如何解决在PowerShell中创建私钥的非系统性问题?

时间:2019-05-29 14:31:27

标签: windows powershell

不幸的是,我们的服务器之一必须使用确定的参数来启动脚本,但他停止了创建私钥的工作,而我坚持了这个问题长达数周之久。每次我在相同条件(相同帐户,服务器,脚本,应用程序)下运行脚本时,它都可以运行,但是在大多数从ServiceDesk应用程序启动的运行中,都以错误结束。

最令人奇怪的是,这种情况多年来一直没有变化。

我已经尝试创建具有私钥创建的后台进程,在不同的AD用户下运行脚本,更改ProviderName字符串中的提供程序,在网络中查找任何解决方案。

服务器为PS版本4“ Windows Server 2012 R2”

发生问题的代码部分:

$PrivateKey = New-Object -ComObject "X509Enrollment.CX509PrivateKey"
$PrivateKey.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"
$PrivateKey.ExportPolicy = 0x1
$PrivateKey.KeyUsage = 0xffffff
$PrivateKey.KeySpec = 0x1
$PrivateKey.KeyProtection = 0x0
$PrivateKey.Length = 2048
$PrivateKey.MachineContext = $False
$PrivateKey.Create()

错误:

Exception calling "Create" with "0" argument(s): "CertEnroll::CX509PrivateKey::
Create: The system cannot find the file specified. 0x80070002 (WIN32: 2 ERROR_F
ILE_NOT_FOUND)"
At C:\Scripts\SD\VPN\ca_renew_cert_company.ps1:125 char:5
+     $PrivateKey.Create()
+     ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

我需要任何有关如何解决问题的信息,有关方法工作的任何链接,任何有帮助的东西。

0 个答案:

没有答案