Hello Luc, thank you for the reply.
You have pointed out some of the same points that I was somewhat not sure how to check the state.
During the build of each of the Windows VMs, they go through rebooting several times in between during the MDT Litetouch deployment sequence. And sometimes it could take a while before the next reboot because of application installs. So the GuestOperationsReady method will not be suitable. I do have the order in which each VM needs to be powered ON. At first I tried to time how long each VM takes to complete the build and place a wait timer for each VM to power ON command but I found sometimes things take longer to complete and it didn't work very well.
I am using a csv file which has an ordered list of VMs which I use for creating the blank VMs on the ESX host. You assisted me on putting a small but very effective snippet together a few years ago and it has served me very well - a big thank you! Below, I have provided the actual script (for others to use) and it would be nice if I could add the logic for powering on each VM into this one simple script.
Add-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue
# Create LAB Virtual Machines from CSV File
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP –confirm:false | Out-Null
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$False | Out-Null
$ESXhost = "192.168.1.10"
$DelayValue = "5000" # 5 Seconds Boot Delay
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
$vmConfigSpec.BootOptions.BootDelay = $DelayValue
$vmConfigSpec.BootOptions.bootOrder += New-Object VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
$vmConfigSpec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$vmConfigSpec.flags.enableLogging = $false
connect-VIServer -Server "$ESXHost" -User "root" -Password "VMware1!"
Import-CSV S:\Automate\labservers.csv -UseCulture | %{
$vm = New-VM -VMhost $ESXhost -Name $_.VMName -MemoryMB $_.MemoryMB -NumCPU $_.NumCPU -Version $_.Version -GuestId $_.GuestId -Datastore $_.Datastore -DiskGB $_.DiskGB -DiskStorageFormat "Thin" -Notes $_.Notes -CD
Get-CDDrive -VM $vm | Set-CDDrive -ISOPath $_.ISOPath -StartConnected $true -Confirm:$false | Out-Null
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $_.NetworkName -Type $_.NICType -MacAddress $_.MAC -StartConnected:$true -Confirm:$False | Out-Null
$vm.ExtensionData.ReconfigVM_Task($vmConfigSpec) | Out-Null
}
Labservers.csv
VMName,MemoryMB,NumCpu,Version,GuestId,Datastore,DiskGB,ISOPath,NetworkName,Notes,NICType,MAC
vanADC01,2048,2,v14,windows9Server64Guest,san0480,32,[SAN0480] iso\MDTProduction.iso,vlan199-van-mgt,*** Domain Controller ***,Vmxnet3,00:50:56:00:56:03
What I was thinking of doing is at the end of the VM build and config process, I could create a blank file called "completed.txt" in C:\Windows\Temp and use something like the Invoke-VMScript command to check if the "completed.txt" is present. Or if the example you have provided could be modified to check for the file?
Thanks,
MP