【问题标题】:Reset 'Friendly Name' certificate property using PowerShell使用 PowerShell 重置“友好名称”证书属性
【发布时间】:2018-09-12 23:40:15
【问题描述】:

我需要将证书的Friendly Name 设置为空值,以便在证书控制台Friendly Name 列中显示<None>。 使用这段代码我能得到的只是列中的空值,而不是我需要的<None>。

 gci "Cert:\LocalMachine\My" | ? {$_.Subject -like "CN=mycer*"} | % { $_.FriendlyName = '' }

我也试过$_.FriendlyName = $null 没有任何区别。

奇怪的事情 - 当我使用控制台清除 Friendly Name 时,从 Powershell 的角度来看,值是 '',因为以下语句产生 True:write-host ($_.FriendlyName -eq '')。但是,反之亦然应用的 ''' 值不能提供预期的结果。

非常感谢任何帮助。

更新和回答: 正如 cmets 中的 Kory Gill 建议的那样,certutil.exe 确实是获得我需要的东西的方法。 创建了一个clear.inf 文件,内容如下

[Version]
Signature = "$Windows NT$"

[Properties]
11 = 

并执行certutil.exe -repairstore -user my "serial number" clear.inf 我设法将Friendly Name 重置为<None> 值。

【问题讨论】:

  • 你为什么不把FriendlyName设置成<None>?
  • @TheIncorrigible1 因为它是另一个<None>。它在属性编辑器中不会显示为空值,而是<None>,这不是我需要的。
  • 那么尝试设置$_.FriendlyName = $null 而不是空字符串?或者你可能需要使用Set-ItemProperty
  • @TheMadTechnician $null 没有任何区别 - 我在发布之前检查了它。至于Set-ItemProperty - 值得一试,明天我回到办公室时会检查。

标签: windows powershell certificate


【解决方案1】:

作为用于管理证书的 PowerShell cmdlet 的替代方法,它可能与某些属性存在问题,也可以使用 certutil.exe 来管理证书。这类似于使用 robocopy.exe 而不是 Copy-File。使用能够为您提供所需结果的工具...

This link 展示了如何使用 certutil 更改友好名称的示例。

该页面的示例用法是:

certutil.exe -repairstore my "{serialnumber}" "change-friendly-name.inf"

inf 文件的样子:

[Version]
Signature = "$Windows NT$"
[Properties]
11 = "{text}new friendly name"

另见certutil reference。

【讨论】:

    猜你喜欢
    • 2010-11-27
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 2020-07-28
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多