【问题标题】:Powershell Select-object from cert store来自证书存储的 Powershell 选择对象
【发布时间】:2014-02-28 08:30:47
【问题描述】:

基本上,我试图通过使用主题来获取证书的序列号,以便可以在 CertUtil 中的变量中使用它。

我离你很近,你会在下面看到有人可以帮忙吗?

cd cert:\localmachine\my

$serno = get-childitem | where { $_.subject -eq "XXXXXXXXXXXXXXXX" } | format-list     -property * | select -property SerialNumber

$serno

这个显示

SerialNumber        
------------ 

不是实际的序列号

有人有线索吗??

【问题讨论】:

    标签: powershell certificate powershell-2.0


    【解决方案1】:

    不要使用format-list,你已经拥有了所有的属性。 format-list 会将你漂亮的 X509Certificate2 对象转换为一组格式对象,这根本不是你想要的。也可以在select 上使用-expandproperty

    PS>get-childitem | where { $_.subject -eq "CN=localhost" } | select -expandproperty SerialNumber
    6191F4A438FF77A24763E6D427749CD7
    

    或者对于 Powershell 3 或更高版本,使用简写符号:

    PS>$serno = (get-childitem | where { $_.subject -eq "CN=localhost" }).SerialNumber
    PS>$serno
    6191F4A438FF77A24763E6D427749CD7
    

    【讨论】:

    • 我把下面的命令和你的例子一样: $serno = get-childitem |其中 { $_.subject -eq "XXXXXXXX.local" } |选择 -expandproperty SerialNumber 并没有返回任何内容
    • 我也不要求它是证书,我需要检索的只是传递给 certutil 的序列号。感谢您在此顺便说一句
    • 邓肯的两个例子都对我有用。我只是替换了我的序列号,我没有更改“CN=localhost”
    • @choco_linux 在您尝试访问SerialNumber 属性时,您确实需要它作为证书。您的format-list 将其全部转换为带有页眉和页脚的文本。如果它仍然不适合您,请说出您仅运行管道的前两个部分或仅运行第一部分时得到的结果。也许你的主题没有完全正确?
    • 当我运行 get-childitem | where { $_.subject -eq "CN=XXXXXXXX.local" } 我得到了我想要的特定证书,但只有两列指纹和主题。我使用 format-list 的最初原因是因为当我执行 -property * 时,它带回了大量有关证书的信息。
    猜你喜欢
    • 1970-01-01
    • 2015-04-20
    • 2011-08-24
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    相关资源
    最近更新 更多