Hi,
I have a script Deploy-VM.ps1 which takes couple of parameters and deploys a VM into a large environment accordingly. The complete deployment procedure for a single VM takes around 10 minutes as I e.g. have to wait for sysprep to complete and the VM to be available on the network to do some post-deployment stuff. The goal is to deploy many thousand VM and doing so sequentially will take around half a year
So what I need is the Deploy-VM script to called multiple time so the tasks can run in parallel - say 10 at a time.
$job = {
.\Deploy-VD.ps1 `
-name $args[0] `
-clusterName $args[1] `
-folder $args[2] `
-template $args[3] `
-custSpecName $args[4] `
-numCPU $args[5] `
-memoryGB $args[6] `
-diskGB $args[7] `
}
Write-Host "Beginning deployment of 5 VDs in parallel..."
Start-Job -ScriptBlock $job -ArgumentList 'vm001', ...
Start-Job -ScriptBlock $job -ArgumentList 'vm002', ...
Start-Job -ScriptBlock $job -ArgumentList 'vm003', ...
Start-Job -ScriptBlock $job -ArgumentList 'vm004', ...
Start-Job -ScriptBlock $job -ArgumentList 'vm005', ...
# wait for all jobs to complete
Get-Job | Wait-Job
Write-Host "Done!"
The problem I have with this this seems to be the vCenter connection. I can create it outside the job block but then it will not be there inside the block. I could add the Connect-VIServer inside the Deploy-VM.ps1 file but then a connection is created for EVERY deployment process and would require me to save the credentials in a variable and push them into the script via parameter.
Everything not every satisfying. Any ideas?
cheers
Mathias