Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Export-csv with multiple field-value expressions?

$
0
0

I'm trying to get all the field-value pairs into the same CSV.

 

## Works Individually ##

 

    $cert = Get-ChildItem cert:\localmachine -Recurse

 

    ($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Key Usage"}).Format(0) | Select-Object -Property @{Name=Key Usage";Expression={$_}} |`

    Export-csv -Path .\KeyUsage.csv

 

    ($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Basic Constraints"}).Format(0) | Select-Object - Property @{Name="basic constraints";Expression={$_}} |`

    Export-csv -Path .\BasicConstraints.csv

 

 

## Does not work ##

 

    $cert = Get-ChildItem cert:\localmachine -Recurse

 

    ($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Key Usage"}).Format(0) | Select-Object -Property @{Name="Key Usage";Expression={$_}},

    ($cert.Extensions | Where-Object {$_.Oid.FriendlyName -eq "Basic Constraints"}).Format(0) | Select-Object - Property @{Name="basic constraints";Expression={$_}} |`

    Export-csv -Path .\File.csv

 

Perhaps I need to check to see if the field-value is null but how do i check that within the 'Expression'? It doesn't look like I can use if(!$_){}else{} to write in some zero'd values. 


Viewing all articles
Browse latest Browse all 6937

Trending Articles