VMware Cloud Community
sjtmal
Contributor
Contributor

export output of the power cli script

I am using attached script to get vlan id of vms. It is working fine,

How to save export output of the same to a csv?

0 Kudos
5 Replies
martinriley
Hot Shot
Hot Shot

Hi, you could try piping to the Export-Csv cmdlet:

...... | Export-Csv C:\PathToCSVFile

Good luck!

0 Kudos
sjtmal
Contributor
Contributor

Getting empty pipe error. Error is attached.

0 Kudos
BenLiebowitz
Expert
Expert

try this:

$vmList = Get-Content -Path C:\VMs.txt

foreach ($vm in $vmList) 

{

get-vm $vm| %{ write-host $_.Name `t ($_ | Get-VirtualPortGroup | select vlanid)} | export-csv -useculture -notypeinformation -path c:\network.csv

    }

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.
0 Kudos
sjtmal
Contributor
Contributor

Not  working. Creating blank output file. Can see the output in command prompt.

0 Kudos
jrmunday
Commander
Commander

The script is using Write-Host, which means that the output is written to the console (essentially being dropped) and can't be piped to the next command (ie. the export cmdlet).

You could try Write-Output instead of Write-Host but I would be inclined to rewrite the script (but only because I would find it easier to follow with custom columns).

Cheers,

Jon

vExpert 2014 - 2022 | VCP6-DCV | http://www.jonmunday.net | @JonMunday77
0 Kudos