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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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)
#####################################################
all the best
boudjel
Hi All,
I too do have a requirement to restart approx 400 VMs at every Monday 5:00 AM on weekly basis. I am trying to create the task scheduled on vmware with the below script. Its creating the task but, one thing its not creating with date and time and second thing is that I need to create the task for 400 VMs so how can I define a csv file and what will the data format in that. please can some one help me on this.
$vmName = 'TESTVM01'
$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.Wednesday = $true
$spec.Scheduler.Hour = "05"
$spec.Scheduler.Interval = "1"
$spec.Action = New-Object VMware.Vim.MethodAction
$spec.Action.Name = "RebootGuest"
$scheduledTaskManager.CreateScheduledTask($vm.MoRef, $spec)