我正在尝试通过 PowerShell 更新(根)证书的友好名称。
我正在尝试更新的证书在下面的屏幕截图中突出显示(取自 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.0
或 4.0
。
参见 Get-ChildItem for Certificate
我有 Powershell 4.0,我可以毫无问题地更改 FriendlyName。重新启动后,这在 certmgr.msc
中可见。
您可以下载 Powershell 4.0 here .
如果您是 Powershell 初学者,最好使用 Get-ChildItem
而不是 gci
以提高可读性。此外,cd
是 Set-Location
的别名,因此最好在您的脚本中选择一个或另一个以避免混淆。
关于windows - 无法通过 PowerShell 设置证书友好名称(访问被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29509719/