Hashtable with Export-CSV

I export data to csv, and for some reason @ {} is being migrated. Here is an example script.

Get-VM VM | Select Name, @{N="DSFree";E={$_ | Get-Datastore | Select FreeSpaceMB }} | Export-Csv c:\temp\info.csv 

The output of the DSFree column is as follows: @ {FreeSpaceMB = 686704}

How can I stop @ {} when exporting?

Thanks in advance.

+4
source share
2 answers

I cannot try your specific example, but usually -ExpandProperty is the answer:

 Get-VM VM | Select Name, @{N="DSFree";E={$_ | Get-Datastore | Select -expandProperty FreeSpaceMB }} | Export-Csv c:\temp\info.csv 
+3
source

While @EBGreen's answer made me learn something, there is an easier way that I believe in this case:

 Get-VM VM | Select Name, @{N="DSFree";E={($_ | Get-Datastore).FreeSpaceMB }} | Export-Csv c:\temp\info.csv 
+1
source

All Articles