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.