How to display array of string in Powershell into CSV properly ?

Senior IT System Engineer
Senior IT System Engineer used Ask the Experts™
on
Hi People,

I'd like to know how to make the IP address column in the CSV a string of IP address ?

here's the script that I run:

Get-VMHost | Get-VM | Get-VMGuest | Select HostName, OSFullName, IPAddress, VmName | Sort HostName | Export-Csv C:\PRODVM.csv

Open in new window


in the CSV all result is good except the IP address column which returns System.String[]
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
steforIT Security Architect
Commented:
Try
Get-VMHost | Get-VM | Get-VMGuest | Select-Object HostName,OSFullName,IPAddress,VmName | Sort-Object HostName | Export-CSV "C:\PRODVM.csv"

Open in new window

GusGallowsSupport Escalation Engineer
Commented:
I don't have a vmhost to try this on, but I would try the following:
Get-VMHost | Get-VM | Get-VMGuest | Select HostName, OSFullName, [string]IPAddress, VmName | Sort HostName | Export-Csv C:\PRODVM.csv

Open in new window

Commented:
Stefor, the proper way to do it is


Get-VMHost | Get-VM | Get-VMGuest | Select HostName, OSFullName, {$_.IPAddress}, VmName | Sort HostName | Export-Csv C:\PRODVM.csv

Open in new window

Author

Commented:
Thanks anyway.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial