{"id":1222,"date":"2013-03-06T09:00:33","date_gmt":"2013-03-06T14:00:33","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1222"},"modified":"2013-03-04T08:26:53","modified_gmt":"2013-03-04T13:26:53","slug":"remove-vcenter-scheduled-tasks-with-powercli-part-3","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/remove-vcenter-scheduled-tasks-with-powercli-part-3\/","title":{"rendered":"Remove vCenter Scheduled Tasks with PowerCLI (Part 3)"},"content":{"rendered":"<p>In my most recent series on vCenter Scheduled Tasks with PowerCLI, I have provided three functions&#8230;<strong>Get-VIScheduledTasks<\/strong>, <strong>Get-VMScheduledSnapshots<\/strong>, and <strong>New-VMScheduledSnapshot<\/strong>.  To complete the series, I have a final function <strong>Remove-VIScheduledTask<\/strong>.  I don&#8217;t really see the need for this one, as you can easily bulk select scheduled tasks in the vCenter UI and delete them with a single click.  However, in the interest of completeness, here is a rough function that will delete a vSphere scheduled task.  [A more robust\/efficient\/complete function could be written that would accept input from the pipeline. If there is a good use case for this please leave a comment below.]<\/p>\n<p>NOTE: This function requires an additional function: <strong>Get-VIScheduledTasks<\/strong> to find the task by name.  In addition the usage example below requires <strong>Get-VMScheduledSnapshots<\/strong>.  Both functions are available here: <a href=\"http:\/\/enterpriseadmins.org\/blog\/scripting\/get-vcenter-scheduled-tasks-with-powercli-part-1\">New vCenter Scheduled Tasks with PowerCLI (Part 1)<\/a>.<\/p>\n<pre><code class=\"language-1\">\r\nFunction Remove-VIScheduledTask {\r\nPARAM ([string]$taskName)\r\n  (Get-View -Id ((Get-VIScheduledTasks -Full | ?{$_.Name -eq $taskName}).ScheduledTask)).RemoveScheduledTask()\r\n}\r\n<\/code><\/pre>\n<p>Usage example:<\/p>\n<pre>\r\n# This example will find all VM Scheduled Snapshots which \r\n# are not scheduled to run again, then remove each one by name.\r\nGet-VMScheduledSnapshots | \r\n?{$_.NextRunTime -eq $null} | %{ Remove-VIScheduledTask $_.Name }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In my most recent series on vCenter Scheduled Tasks with PowerCLI, I have provided three functions&#8230;Get-VIScheduledTasks, Get-VMScheduledSnapshots, and New-VMScheduledSnapshot. To complete the series, I have a final function Remove-VIScheduledTask. I don&#8217;t really see the need for this one, as you &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/remove-vcenter-scheduled-tasks-with-powercli-part-3\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1222","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1222"}],"version-history":[{"count":7,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1222\/revisions"}],"predecessor-version":[{"id":1229,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1222\/revisions\/1229"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}