当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 PowerShell 中获取证书指纹

作者:精品下载站 日期:2024-12-15 00:31:20 浏览:15 分类:玩电脑

在 PowerShell 中获取证书指纹


证书指纹是证书或哈希的唯一标识符,用于标识特定的数字证书。使用带有证书存储位置路径的 Get-ChildItem cmdlet,它会检索所有证书并获取证书指纹、到期日期等...

证书的 Thumbprint 属性用于在 PowerShell 中获取证书哈希。

在本文中,我们将讨论如何使用 PowerShell 中的 Get-ChildItem cmdlet 获取存储在 LocalMachine 存储中的证书的指纹。

在 PowerShell 中检索证书指纹

使用 PowerShell 中的 Get-ChildItem cmdlet,该 cmdlet 使用 Path 参数指定证书存储位置并检索所有证书以及证书的指纹、友好名称和过期日期。

运行以下命令以使用 PowerShell 脚本获取证书指纹。

Get-ChildItem -Path 'cert:\LocalMachine\My' | Select Thumbprint,FriendlyName,NotAfter 

在上面的 PowerShell 脚本中,Get-ChildItem cmdlet 获取存储在 LocalMachine\My 证书存储位置中的所有证书。它将输出传递给 Select 命令以获取证书指纹和证书到期日期。

上述用于检索证书指纹的脚本的输出是:

[玩转系统] 在 PowerShell 中获取证书指纹

酷提示:如何在 PowerShell 中通过指纹查找证书!

使用 PowerShell 获取证书的指纹

PowerShell 中的 Get-ChildItem cmdlet 检索存储在 LocalMachine\My 证书存储位置路径中的所有证书。要筛选结果或获取特定证书的指纹,请使用 Where-Object cmdlet。

Get-ChildItem -Path 'cert:\LocalMachine\My' | Where-Object { $_.Subject -eq 'CN=localhost' } 

在上面的 PowerShell 脚本中,Get-ChildItem cmdlet 使用 Path 参数指定 LocalMachine\My 证书存储位置路径。

它检索所有证书并将它们传递给 Where-Object cmdlet。 Where-Object cmdlet 使用 -eq 运算符检查证书的主题属性是否等于证书的主题。

上述用于过滤证书以根据 Subject 属性检索证书指纹的 PowerShell 脚本的输出为:

PS C:\> Get-ChildItem -Path 'cert:\LocalMachine\My' | Where-Object { $_.Subject -eq 'CN=localhost' }                                                                                         

   PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My

Thumbprint                                Subject
----------                                -------
984E459FF99D87FD97AFC46DCDCBCB90E0B7FCD5  CN=localhost

酷提示:如何在PowerShell中获取证书序列号!

结论

我希望上述有关如何在 PowerShell 中使用 Get-ChildItem cmdlet 和 Thumbprint 属性获取证书指纹的文章对您有所帮助。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯