1

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.

2
  • Welcome to stack overflow! You need to include way more detail. Commented Jun 29, 2010 at 23:43
  • Is the script the same for each VC server? Commented Jun 30, 2010 at 0:11

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

foreach is what you want I think

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.