VMware Cloud Community
robinstolpe
Enthusiast
Enthusiast
Jump to solution

Remove SchedualTasks?

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

}

 

IT engineer that works with the hole VMWare portfolio and also loves to develop and automate in C# and PowerShell
0 Kudos
1 Solution

Accepted Solutions
robinstolpe
Enthusiast
Enthusiast
Jump to solution

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()
}
}
IT engineer that works with the hole VMWare portfolio and also loves to develop and automate in C# and PowerShell

View solution in original post

0 Kudos
1 Reply
robinstolpe
Enthusiast
Enthusiast
Jump to solution

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()
}
}
IT engineer that works with the hole VMWare portfolio and also loves to develop and automate in C# and PowerShell
0 Kudos