{"id":1317,"date":"2014-09-12T12:37:06","date_gmt":"2014-09-12T11:37:06","guid":{"rendered":"http:\/\/blog.repsaj.nl\/?p=1317"},"modified":"2014-09-12T12:37:06","modified_gmt":"2014-09-12T11:37:06","slug":"sp201x-terminating-runnning-workflows-with-powershell","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2014\/09\/sp201x-terminating-runnning-workflows-with-powershell\/","title":{"rendered":"[SP201x] Terminating runnning workflows with Powershell"},"content":{"rendered":"<p>After importing \/ restoring a site collection from a different environment, you might have the need to terminate all of the running workflows. For instance, to stop them from e-mailing people or firing off other events which should not be fired from within your local dev environment. Whatever reason you might have, here is a little Powershell script which can help you do so:<\/p>\n<pre class=\"prettyprint\">\r\nAdd-PSSnapIn Microsoft.SharePoint.Powershell \r\n\r\n$url = \"http:\/\/localhost:1234\"\r\n\r\n$web = Get-SPWeb $url \r\n$web.AllowUnsafeUpdates = $true;\r\n\r\ntry \r\n{\r\n\t$i = 0\r\n\tfor ($i = $web.Lists.Count; $i -ge 0; $i--)\r\n\t{\r\n\t\tforeach ($item in $web.Lists[$i].Items)\r\n\t\t{\r\n\t\t\tforeach ($workflow in $item.Workflows)\r\n\t\t\t{\r\n\t\t\t\tif ($workflow.IsCompleted -ne $true)\r\n\t\t\t\t{\r\n\t\t\t\t\t[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow)  \r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tforeach ($workflow in $web.Workflows)\r\n\t{\r\n\t\tif ($workflow.IsCompleted -ne $true)\r\n\t\t{\r\n\t\t\t[Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($workflow)  \r\n\t\t}\r\n\t}\r\n}\r\nfinally {\r\n\t$web.AllowUnsafeUpdates = $false\r\n\t$web.Update()\r\n\t$web.Dispose()\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>After importing \/ restoring a site collection from a different environment, you might have the need to terminate all of the running workflows. For instance, to stop them from e-mailing people or firing off other events which should not be fired from within your local dev environment. Whatever reason you might have, here is a<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[45,7,39,92],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-lf","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1317"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=1317"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1317\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=1317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=1317"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=1317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}