Powershell证书扩展程序export-csv

时间:2015-10-26 20:58:38

标签: csv powershell x509certificate export-to-csv

我试图将证书扩展名收集到csv中。 PowerShell命令似乎在PowerShell中显示得很好,但是当通过管道传输到csv时,它们会显示其他类型的数据?

$cert = Get-ChildItem cert:\localmachine -Recurse
($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Key Usage"}).Format(1) | Export-Csv C:\Folder\File.csv

搜索网页后,我尝试了不同的功能,但仍然无法像PowerShell中那样获取和显示数据。

$cert=Get-ChildItem cert:\localmachine -Recurse           
$sanExt=$cert.Extensions | Where-Object {$_.Oid.FriendlyName -match "subject alternative name"}            
$sanObjs = new-object -ComObject X509Enrollment.CX509ExtensionAlternativeNames            
$altNamesStr=[System.Convert]::ToBase64String($sanExt.RawData)            
$sanObjs.InitializeDecode(1, $altNamesStr)            
Foreach ($SAN in $sanObjs.AlternativeNames) {$SAN.strValue}
$sanExt.Format(1) | Export-Csv C:\Folder\File.csv

1 个答案:

答案 0 :(得分:0)

对于其他想要收集扩展字段的人来说,这是我的决议:

$cert = Get-ChildItem cert:\localmachine -Recurse
($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Key Usage"}).Format(1) |
Select-Object -Property @{Name="Certificate";Expression={$_}} |
Export-csv -Path C:\Folder\file.csv`