【发布时间】:2020-02-27 12:05:07
【问题描述】:
我正在尝试将单个自签名证书分发到多个服务器,并分发到一组服务帐户的个人证书存储中。此证书将用于解密只有服务帐户才能读取的敏感文件。
证书创建如下:
New-SelfSignedCertificate -DnsName CredentialVault `
-CertStoreLocation "Cert:\CurrentUser\My" `
-KeyUsage KeyEncipherment,DataEncipherment -Type DocumentEncryptionCert `
-KeyAlgorithm RSA -KeyLength 2048
$computer = 'SERVER123.EXAMPLE.COM'
$cred = New-Object PSCredential 'MYDOMAIN\USER213', `
$(ConvertTo-SecureString -String 'P4$$w0Rd' -AsPlainText -Force)
$scriptBlock = {
Import-PfxCertificate -FilePath 'C:\temp\CredentialVault.pfx' `
-Password $(ConvertTo-SecureString -String '1234' -AsPlainText -Force) `
-CertStoreLocation "Cert:\CurrentUser\My"
}
Invoke-Command -ComputerName $computer -Credential $cred -ScriptBlock $scriptBlock
我在服务器 SERVER123.EXAMPLE.COM 上执行代码(但使用不同的帐户),只是想在尝试远程服务器之前看看它是否可以工作。这就是文件路径引用本地文件的原因。
但是,即使MYDOMAIN\USER213 帐户可以访问该文件(我首先在与该用户相同的服务器上直接测试了Import-PfxCertificate 命令),PowerShell 仍会返回System.IO.FileNotFoundException,如下所示。
The PFX file could not be found.
+ CategoryInfo : NotSpecified: (:) [Import-PfxCertificate], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.CertificateServices.Commands.ImportPfxCertificate
+ PSComputerName : SERVER123.EXAMPLE.COM
我不知道问题是什么。欢迎提出建议!
版本信息:
- Windows Server 2016
- PowerShell 5.1.14393.3471
【问题讨论】: