VMware Cloud Community
VicMware
Contributor
Contributor

powershell question

Hi

I wrote a loop to retrieve vcenter name $a, cluster name $b and $c folder name in the environment.

How do I display it in excel spreadsheet?

Here is an example:

$i =0

while ($i -neq 10) {

$a = $i+1 #display in first raw column 1

$b = $i+2 #display in first raw column 2

$c = $i+3 #display in first raw column 3

$i++

#Add $a, $b and $c to the row $i

}

The output I am expecting is

1 2 3

2 3 4

3 4 5

.

.

.

0 Kudos
1 Reply
LucD
Leadership
Leadership

You can do something like this

$i =0
$report = @()
while ($i -neq 10) {
 
$row = "" | Select a,b,c
 
$row.a = $i + 1 #display in first raw column 1
  $row.b = $i + 2 #display in first raw column 2
  $row.c = $i + 3 #display in first raw column 3
  $i++
 
#Add $a, $b and $c to the row $i
  $report += $row
}

$report | Export-Csv report.csv -NoTypeInformation -UseCulture

Create a $row object with the properties.

Assign the values to the properties.

Add the $row object to an array, and then export that array to a CSV file


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

0 Kudos