简体   繁体   中英

Hashtable with Export-CSV

I am exporting data to a csv and for some reason the @{} are transferring over. Here is a sample 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 looks like this: @{FreeSpaceMB=686704}

How can I stop the @{} from exporting?

Thanks in advance.

I can't try your specific example, but typically -ExpandProperty is the answer:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM