VMware Cloud Community
thisischristia1
Contributor
Contributor

For-Each | Export-CSV - Multiple vCenters to One Excel File using worksheets

So i have around 20 or more vCenters that i typically run reports for. What i am looking for is a seemless way to execute any script against the list of 20 vCenters and output the data into the excel CSV, but into One file using multiple worksheets within the file. So ideally if I have 20 tabs, 1 tab for each output for each individual vcenter, a script to run against the list of vCenters, and a list of 20 individual vcenters in a txt file.

How would i accomplish this? 

1 Reply
LucD
Leadership
Leadership

You will need to use the ImportExcel module.

As a very simple example (I assume you are already connected to all vCenters).

$xlsFile = 'C:\Temp\report.xlsx'

foreach($vc in $global:DefaultVIServers){

    $report = Get-VM -Server $vc | Select Name,PowerState

    $report | Export-Excel -Path $xlsFile -WorkSheetname $vc.Name

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference