VMware Cloud Community
DennieTidwell
Enthusiast
Enthusiast
Jump to solution

Format output via Export-CSV to include spaces in row headers?

Format output via Export-CSV to include spaces in row headers? I get errors when placing spaces in code.

How can I export data via export-csv to place spaces in header row? ie. in below script ... I need the VMName and IPAddress header rows to have spaces in them like "VM Name" and "IP Address"?

*****************

Get-VM | %{

$vmGuest = $_ | Get-VMGuest

$row = "" | Select VMName, State, OS, Host, CPU, IPAddress

$row.VMname = $_.Name

etc .....

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can place spaces in object properties like this:

Get-VM | %{
  $vmGuest = $_ | Get-VMGuest
  $row = "" | Select "VM Name", State, OS, Host, CPU, "IP Address"
  $row."VM Name" = $_.Name
etc .....

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can place spaces in object properties like this:

Get-VM | %{
  $vmGuest = $_ | Get-VMGuest
  $row = "" | Select "VM Name", State, OS, Host, CPU, "IP Address"
  $row."VM Name" = $_.Name
etc .....

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos