tags:

views:

59

answers:

3

I have a several scripts that are using PowerCLI to pull info from all of our virtual center servers and dumping into an HMTL file. At this time I have one script setup for each virtual center server, howerver I want to modify it so that I have one main script that will loop through each virtual center and create a HTML for each one instead of having to maintain several different scripts. I have tried declaring each VC as a variable, for example:

$vc = "vc1" , "vc2"

however that only generated one HTML file using the last variable. What would be the best way to accomplish this? Thanks for any help.

+1  A: 

Here is a tutorial on looping in Powershell, hope it helps.

Nathan
A: 

foreach is what you want I think

Yanagi
+1  A: 

Try this:

"Server01","Server02" | ForEach-Object {
  Connect-VIServer -Server $_ -User user -Password password;
}

Also add the rest of the code that you need to apply to each Server with in the ForEach-Object's { }. You can then name each HTML file with the $_ (server name inside the loop) variable as well.

Jonny