windows - 无法通过 PowerShell 设置证书友好名称(访问被拒绝)

标签 windows powershell certificate powershell-2.0

我正在尝试通过 PowerShell 更新(根)证书的友好名称。

我正在尝试更新的证书在下面的屏幕截图中突出显示(取自 certmgr.msc):

certmgr.msc

这是 PowerShell 代码(大部分取自 here ):

Set-Location cert:
cd .\CurrentUser\Root
$cert = gci .\02FAF3E291435468607857694DF5E45B68851868
$cert.FriendlyName = "UserTrust CA"

(我已经用 certmgr.msc 中的证书属性验证了指纹,以确保它是同一个证书)。

最后一行会导致以下错误:

Exception setting "FriendlyName": "Access is denied.
"
At line:1 char:7
+ $cert. <<<< FriendlyName = "UserTrust CA"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

到目前为止,我已经尝试过以下方法:

  • 以管理员身份运行 PowerShell
  • 使用以下方法更改执行策略:Set-ExecutionPolicy Unrestricted

其他信息:

  • PowerShell 版本为 2.0(在 Windows 7 Enterprise x64 上运行)
  • 我正在运行 PS 的 x64 版本
  • DEP 和 UAC 已禁用
  • 我的帐户是 Administrators 组的一部分
  • 我是一个完整的 PowerShell n00b ;-)

PS版输出:

$PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

最佳答案

您需要将您的 Powershell 版本更新到 3.04.0。 参见 Get-ChildItem for Certificate

我有 Powershell 4.0,我可以毫无问题地更改 FriendlyName。重新启动后,这在 certmgr.msc 中可见。

您可以下载 Powershell 4.0 here .

如果您是 Powershell 初学者,最好使用 Get-ChildItem 而不是 gci 以提高可读性。此外,cdSet-Location 的别名,因此最好在您的脚本中选择一个或另一个以避免混淆。

关于windows - 无法通过 PowerShell 设置证书友好名称(访问被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29509719/

相关文章:

windows - 如何在 Windows 上使用 GNU Make?

java - 如何使用 PEM 文件在 Java 中创建 SSL 套接字?

PowerShell,具有 -Depth 输出的 Get-ChildItem

https - 如何使用 VBSCRIPT 并接受所有证书来使用 HTTPS 连接下载文件

security - 如何使用JAVA URL httpsconnection发送没有证书的https请求

windows - Windows 锁定时向程序发送热键

python - pip 安装包时出现问题

c++ - 接收大量 (r) UDP 流量时 CPU 负载高 (Windows)

azure - "az ad app permission list-grants"与 Azure 门户中为应用程序列出的内容不匹配

powershell - 使用 PowerShell 删除重复字符串