Automation

 View Only
  • 1.  Remove SchedualTasks?

    Posted Dec 04, 2021 07:28 AM

    Hi,

    I want to remove all schedualtasks for some VM's in vSphere with PowerCli I have found how I can add schedualtasks but not how I can delete them?

    $VMs = get-vm te*

    foreach ($vm in $vms) {

    # Remove all schedualtaks for a VM

    }

     



  • 2.  RE: Remove SchedualTasks?
    Best Answer

    Posted Dec 04, 2021 08:00 AM

    Found it

     

    $CollectVMs = Get-VM -name *

     

    foreach ($vm in $CollectVMs) {
    $vmObj = Get-VM -Name $vm
    $si = Get-View ServiceInstance
    $scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
    Get-View -Id $scheduledTaskManager.ScheduledTask |
    where { $vmObj.ExtensionData.MoRef -contains $_.Info.Entity } | % {
    $_.RemoveScheduledTask()
    }
    }