Hey guys! I am writing a script that will back up our Hyper-V machines. I want to do them at the same time but then wait for them all to be done...I'll need to move the files when they are finished.
My question is, will this work? I haven't tested it but I think it should show you the general idea of what I want. I need to store the jobs in an array...then loop through the array waiting for them all to be finished or failed, anything but running. Does the following code look ok?
Remove-Item "C:\Backup\*" -Recurse $jobs[0] = Export-VM -Name COMPANYWEB -Path "C:\Backup" -AsJob $jobs[1] = Export-VM -Name TFSDeploy -Path "C:\Backup" -AsJob $jobs[2] = Export-VM -Name OldVSS -Path "C:\Backup" -AsJob $jobs[3] = Export-VM -Name MattBuild -Path "C:\Backup" -AsJob $jobs[4] = Export-VM -Name PSR -Path "C:\Backup" -AsJob $jobs[5] = Export-VM -Name XPPortal -Path "C:\Backup" -AsJob $done = true do { for ($i = 0; $i -le 6; $i++) { if ($jobs[$i].status -eq "Running") $done = false } } while ($done -eq false)
- Edited by GaidenFocus Tuesday, March 31, 2015 3:42 PM