2 Replies Latest reply on Jun 13, 2018 2:51 AM by boudjel38xpo

    Create a scheduled reboot task for 700 VM in vcenter

    boudjel38xpo Lurker

      Hi,

      my goal is to create a reboot vm task guest os on a weekly basis every sunday night in vcenter

      i have roughly 700 VM and i need to add a reboot task in vcenter for each vm

      how can i automate the task creation for all vm ?

      as far as i know there is no cmdlet command yet available to create vm tasks

      is it possible ? perhaps there is a way around cmdlets commands....

      any help will be appreciated

      thanks

      boudjel

        • 1. Re: Create a scheduled reboot task for 700 VM in vcenter
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          Have a look at Re: Creating a scheduled task to shutdown and reboot a VM

          That creates a task for 1 specific VM, but you can easily use that code in a ForEach loop for all your VMs.

          • 2. Re: Create a scheduled reboot task for 700 VM in vcenter
            boudjel38xpo Lurker

            Hi LucD,

             

            thank you for pointing me in the right direction :)

            i had to change a bit the code but it worked !

            i will try to add the loop for my vms 

            below is the code if anyone might have the same thing to do

            this restart the guest os every Sunday at 3 PM (UTC time)  :

            ########################################################## 

            $vmName = 'myvm'
            $si = Get-View ServiceInstance
            $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
            $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName}
            $spec = New-Object VMware.Vim.ScheduledTaskSpec
            $spec.Name = "Restart $($vmName)"
            $spec.Description = "Restart $($vmName)"
            $spec.Enabled = $true
            $spec.Scheduler = New-Object VMware.Vim.WeeklyTaskScheduler
            $spec.Scheduler.Sunday = $true
            $spec.Scheduler.Hour = "3"
            $spec.Scheduler.Interval = "1"
            $spec.Action = New-Object VMware.Vim.MethodAction
            $spec.Action.Name = "RebootGuest"
            $scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)


            #####################################################

            ########################################################## 
             
            $vmName = 'FRA-VSD-50511_VCENTER_windows_dev_6.5'
            $si = Get-View ServiceInstance
            $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
            $vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$vmName}
            $spec = New-Object VMware.Vim.ScheduledTaskSpec
            $spec.Name = "Restart $($vmName)"
            $spec.Description = "Restart $($vmName)"
            $spec.Enabled = $true
            $spec.Scheduler = New-Object VMware.Vim.WeeklyTaskScheduler
            $spec.Scheduler.Sunday = $true
            $spec.Scheduler.Hour = "3"
            $spec.Scheduler.Interval = "1"
            $spec.Action = New-Object VMware.Vim.MethodAction
            $spec.Action.Name = "RebootGuest"
            $scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)
             
             
            #####################################################

            all the best

            boudjel