Powershell 如何访问有错误的证书:“;无法检索证书,因为指纹无效";

Powershell 如何访问有错误的证书:“;无法检索证书,因为指纹无效";,powershell,permissions,certificate,certificate-store,Powershell,Permissions,Certificate,Certificate Store,我发现了错误 无法检索证书,因为指纹无效。 验证指纹,然后重试 当我尝试在LocalMachine证书存储中使用证书时 我已经让管理员帐户在LocalMachine证书存储中安装了证书(包括私钥),并为某些用户提供了私钥访问权限(例如,功能ID) 我希望能够运行以下代码来获取指纹,然后在调用Invoke WebRequest时使用指纹: $certStorePath = "Cert:\LocalMachine\My" $certDetails = Get-ChildI

我发现了错误

无法检索证书,因为指纹无效。 验证指纹,然后重试

当我尝试在LocalMachine证书存储中使用证书时

我已经让管理员帐户在LocalMachine证书存储中安装了证书(包括私钥),并为某些用户提供了私钥访问权限(例如,功能ID)

我希望能够运行以下代码来获取指纹,然后在调用
Invoke WebRequest
时使用指纹:

$certStorePath  = "Cert:\LocalMachine\My"
$certDetails    = Get-ChildItem -Path $certStorePath | Where-Object {$_.Subject -like "*myCert*"}   # Returns one result
$certThumbprint = $certDetails.Thumbprint

Invoke-WebRequest -Uri $externalUrl -Proxy $proxyServer -UseBasicParsing -CertificateThumbprint $certThumbprint
我可以获取证书的详细信息,包括指纹($certDetails),但似乎权限不允许我(或FID)使用证书(或者可能只是访问证书的私钥部分)。当证书安装在CurrentUser存储中时,该代码起作用


如何为这些非管理员用户启用对LocalMachine存储中证书的访问?

问题似乎与
调用WebRequest以及如何在这段代码中使用有关

代码的第一部分能够成功访问证书:

$certStorePath=“Cert:\LocalMachine\My”
$certDetails=Get-ChildItem-Path$certStorePath |其中对象{$\类主题“*myCert*”}
但是,尽管指纹在所有证书存储中都是唯一的(例如,此指纹仅存在于LocalMachine中),
Invoke WebRequest
无法访问它,因为它将只在CurrentUser证书存储中查找

因此,总的来说,要使这项工作发挥作用:

  • 安装包含私钥的证书
  • 向适当的用户/FID提供对证书私钥部分的访问
  • 使用
    Get ChildItem
    获取证书本身,并将其传递给
    Invoke WebRequest
    而不是指纹:
  • $certStorePath=“Cert:\LocalMachine\My”
    $certificate=Get ChildItem-Path$certStorePath |其中对象{$\类Subject“*myCert*”}返回一个结果
    调用WebRequest-Uri$externalUrl-Proxy$proxyServer-UseBasicParsing-Certificate$Certificate