Cancelling all Workflow Associated with SharePoint List using PowerShell

In our SharePoint environment, if there are multiple users accessing the workflow at the same time, you may need to cancel the long running workflow that prevents you from Environment instability.
 
Here are the PowerShell Commands to cancel all the workflows associated with a SharePoint Library or List.
  1.    
  2. $web = Get-SPWeb "http://mysite";  
  3. $web.AllowUnsafeUpdates = $true;  
  4.   
  5.   
  6. $list = $web.Lists["EmployeeMaster"];  
  7.  
  8. # Iterate through all Items in List and all Workflows on Items.  
  9. foreach ($item in $list.Items) {  
  10. foreach ($wf in $item.Workflows) {  
  11.  
  12. #Cancel Workflows  
  13. [Microsoft.SharePoint.Workflow.SPWorkflowManager]::CancelWorkflow($wf);  
  14. }  
  15. }  
  16. $web.Dispose();  
  17.    
Happy SharePointing :-)