Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180923

How to pass parameters in a variable in a loop FOREACH ?

$
0
0

Hello everyone

 

I opened a new topic because I need your lights.

 

I have a script that allows me to automatically create multiple virtual machines.

I would now like to put parameters into a variable so that I can from select from my command prompt the number of machines at create and the name of machines.

 

I tried the variable args [] but it does not work in a foreach loop.

 

Here my script:

 

Connect-VIServer -Server 10.*.*.* -Protocol https -User admin-Password admin

2..$args[0] | Foreach {
New-vm -vmhost Server1.rio.paris.eu -Name "$args[1]$_" -Template TestScript -Datastore Database_1

}

2..$args[0] | Foreach {
Start-VM -VM "$args[1]$_"
}

 

In this script, the variable "$args[0]" to indicate the number of machine created and  the variable "args[1]" to indicate the name of the machines.

 

But it does not work.

 

I hope to have been clear on my problem.

 

Thanks so much for your help.


Viewing all articles
Browse latest Browse all 180923

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>