My SharePoint Adventures
Start a workflow using PowerShell
Requirement
Start a workflow on all / specific items in a list.
Change the site and workflow names to suit your requirements. I included a condition in this script to only start the workflow on items where ‘Status’ is not equal to Complete. You can remove this condition if you wish to run the script on all items in the list.
Solution
Use a PowerShell script to start the workflow.
#Site and List $SPAssignment = Start-SPAssignment $web = Get-SPWeb "http://your-site" -AssignmentCollection $spAssignment $site = Get-SPSite "http://webservices.rcrtom.com.au" $listToCancel = "your-list"; $web.AllowUnsafeUpdates = $true; #Output file $Today = Get-Date -Format "dd-M-yy" $outFile = "c:\CancelWorkflowScript-Log-$Today.txt" #Workflows to Remove $wfToStart= "Name of workflow" #List Name $list = $web.Lists[$listToCancel]; #Workflow Manager $manager=$site.WorkFlowManager $association=$list.WorkFlowAssociations | where {$_.Name -eq $wfToStart} $association.AllowAsyncManualStart = $true $association.AllowManual = $true # Iterate through all Items in List and all Workflows on Items. #Filtered List Write-Host "Restarting workflows.." foreach ($item in $list.Items) { if ($item["Status"] -ne "Completed") { $data=$association.AssociationData $wf=$manager.StartWorkFlow($item,$association,$data) Write-Output "$wftoStart started on " $item.Name | Out-File $outFile -Append } else { Write-Output $item.Name " - is completed " | Out-File $outFile -Append } } Write-Host Finished. $web.Dispose() $site.Dispose() |
Note: Workflows started using via PowerShell like this do not trigger other workflows when they complete, even if you have other workflows set to automatically start on item change.
If you enjoyed this article, please consider sharing it!
Categories
Recent Posts
- Short break
- Speed up SharePoint using the IIS Blobcache
- Could not generate mail report.An exception occurred while executing a Transact-SQL statement or batch.No global profile is configured. Specify a profile name in the @profile_name parameter.
- Microsoft SharePoint is not supported with version 4.0.30319.296 of the Microsoft .Net Runtime.
- PowerShell script to update all Site Collection Owners
Popular Posts
- SharePoint Keeps Prompting for Credentials Problem SharePoint keeps prompting you for credentials in the following scenarios: You ...
- Security Token Service Application- Broken Problem Had an issue today on one of my developer's VMs. ...
- User Profile Service Stuck on Starting Problem You have followed Harbar's Rational Guide to setting up the ...
- Event 8313 Topology – Load Balancer EndpointFailure – SearchService.svc Problem Encountered the following error while analysing the logs on our ...
- Event 6398 and 5586 SharePoint Foundation Problem Event logs were getting filled with the following errors: Event 5586, ...
- The security validation for this page is invalid Problem: After applying SharePoint 2010 Service Pack 1 and June 2011 ...
- The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. Problem You install .NET Framework 4.0 on your SharePoint 2010 WFE ...
- Start a workflow using PowerShell Requirement Start a workflow on all / specific items in a ...
- Using Export-SPWeb to export libraries / lists This is a simple one but many people get the ...
- Unable to change User Profile Service Account Problem So you made a mistake by trying to change the ...
Tags
Backup and Restore Branding Content Management Content Organizer database Debugging Document Conversion Service DPM Event 7362 Expiration Policy IIS InfoPath Information Management Javascript KB2266203 Masterpage Migration Mysite OCS Office Page Layouts PowerPivot Powershell RBS Records Center Regional Settings Search Search Center Security Send-to Connection SharePoint Diagnostic Studio SharePoint Manager Solutions SPD Uploading Usage and Health Data Collection User Profile Service Visual Upgrade Web Analytics Web Content Management Webdav Webparts Workflow WSS XSLT
