VMware Cloud Community
drivera01
Enthusiast
Enthusiast

script to create snapshots


I created a basic script for creating snapshots. I honestly spent much more time on the reporting aspect of the script on how it reports the completions of the vms snaps. Same goes for deleting of the snaps..too much time spent on the reporting aspec.  Smiley Happy



now my issue, my script just runs in a loop based off a file with VM names.  the amount of vms I have to snap makes it impossible to do it this way  because of my limited window to create the snaps, My script basically does one at a time, once one finishes it works on the next one.


Is there a way to parallelize it a bit to run more than one snap at a time?


As I mention the actual vm snap part is just basic as seen here... maybe I should spend more time on the meat and potatoes of the scrpt  than the fancy smancy reporting to go with this script...:)



foreach ($vm in $vmlist)
   {
     New-Snapshot -VM $vm -Name "snapshot-name-here" -Memory:$true -Confirm:$false
     
   }

Has anyone thought about this before?  maybe running 2 or 3 snaps at a time.. I dont want to run too many at one time but  if I could do 2 or 3 at a time that would greatly reduce the overall time needed.

0 Kudos
3 Replies
mattboren
Expert
Expert

Hello, dj-

Have a look at using the -RunAsync parameter to New-Snapshot.  When using this parameter, "the command returns immediately without waiting for the task to complete".

Then, it is just a matter of handling some throttling of the snapshot tasks (or let vCenter handle that throttling).  That help?

0 Kudos
Chrisxxxx
Contributor
Contributor



  To handle the throttling you could modify this function I( wrote.  http://poshcode.org/4880   "Wait-mTaskvMotions.ps1"

0 Kudos
drivera01
Enthusiast
Enthusiast


if I do not place any throttling in my script, how many snapshots can be started at one time before they start queuing up?

0 Kudos