Automation of the new VM in the background (as the task or work)

Hello guy

Need you help again...

I am trying to automate the creation of virtual machines. but to do this in the background, I played with the Wait-task and the Start-Job cmdlet, but didn't success to make it work.

The script change a customization specification, create the new virtual machine, game - vm with cpu/memory settings, updated hot hot-plug/add settings and turn on the virtual machine, looks like this:

Get-OSCustomizationSpec $NewVM_OSCustomizationSpec |
Get-OSCustomizationNicMapping |
Game-OSCustomizationNicMapping - IpMode: 'UseStaticIP' - the $NewVM_Ipaddress IpAddress
SubnetMask - $NewVM_SubnetMask - passerelle_par_defaut $NewVM_Gateway '
DNS - $DNS

$NewVM_OSCustomizationSpec - FullName $NewVM_ServerName
"New-VM-name $NewVM_ServerName-model $NewVM_Template"
-VMHost $NewVM_ESXHost - Datastore $NewVM_Datastore '
OSCustomizationSpec - $NewVM_OSCustomizationSpec-location $NewVM_Folder #-RunAsync

Set-VM - $NewVM_ServerName NumCpu VM - $NewVM_CPU - MemoryMB $NewVM_RAM-confirm: $false

$VM = get - VM $NewVM_ServerName
$Spec = new-Object VMware.Vim.VirtualMachineConfigSpec
$Spec.memoryHotAddEnabled = $true
$Spec.cpuHotAddEnabled = $true
$Spec.NumCoresPerSocket = 1
$VM. ExtensionData.ReconfigVM_Task ($spec)
Start-VM $VM

My problem is that if I run the game - vm until the task of the new vm is complete, of course, it doesn't, I need to set up tasks for work one by one, after waiting each task to be completed before starting the new task, but to him everything in the background,

Please help me if you can.

Thank you very much, I appreciate all the help

I suspect that the background task may be waiting for something.

Try to disable the warnings to begin with, add the following line at the top of your script block Start-Job.

$WarningPreference = "SilentlyContinue".

BTW, have you given up on the RunAsync?

Tags: VMware

Similar Questions

Maybe you are looking for