سؤال

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top