Hi,
I am unable to get the output from below script to csv as it shows Length in the output. the screen output shows correctly but unable to get the correct output n csv. Please help
$RDMNAAs = Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select -ExpandProperty ScsiCanonicalName -Unique
$RDMNAAs | ft -auto
$RDMNAAs | Export-Csv -Path ".\RDM_Info.csv" -NoTypeInformation -UseCulture
That is due to the ExpandProperty.
Export-Csv expects objects with a Name and a Value, with ExpandProperty you only provide a Value (a String).
This should work
$RDMNAAs = Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select -Property ScsiCanonicalName -Unique
$RDMNAAs | Export-Csv -Path ".\RDM_Info.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is due to the ExpandProperty.
Export-Csv expects objects with a Name and a Value, with ExpandProperty you only provide a Value (a String).
This should work
$RDMNAAs = Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select -Property ScsiCanonicalName -Unique
$RDMNAAs | Export-Csv -Path ".\RDM_Info.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Actually the result is correct because the "Export-CSV" method exports the properties of the object. Could you use Out-File method and export the result in csv file format ?
Maya
I'm afraid that is not correct, the Export-Csv expects an object (Name & Value).
When it only gets a String, it will show the length of that string in the CSV.
Working via Out-File and giving the file a CSV extension will also not work unless you first write a line with the column headers.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, Luc!
Thank you very much LucD. that worked.