VMware Cloud Community
ANSUDHARSON
Contributor
Contributor
Jump to solution

Write-Host Returns the right Datastore value while Export-CSV does not

Hi Team

I am using the attached script to obtain the inventory from vcenter. All works well but the output to a CSV gives the datasore value as "VMware.Vim.VirtaulMachineConfigInfoDatastroreUrlPair[]" instead of the actual Datastore name.

But when I do a write-host in the end (instead of exporting to CSV) I do find the datastore name reflecting correctly.

Can someone help me figure out what i am missing?

Thanks in advance.

Sudharson AN

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The problem is that the the vm can have multiple datastores and the DatastoreUrl is an object and not a string.

Try changing:

$Report.DatastoreName = $VMview.Config.DatastoreUrl


into:

$Report.DatastoreName = [string]::Join(" ",($VMview.Config.DatastoreUrl | Select-Object -Expandproperty Name))
Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The problem is that the the vm can have multiple datastores and the DatastoreUrl is an object and not a string.

Try changing:

$Report.DatastoreName = $VMview.Config.DatastoreUrl


into:

$Report.DatastoreName = [string]::Join(" ",($VMview.Config.DatastoreUrl | Select-Object -Expandproperty Name))
Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos