Tag Archives: Workflows

Restart SharePoint 2013 Workflows with PowerShell

Recently I had an issue where my #SharePoint list #workflows wouldn’t run and were in suspended state. The reason for the suspended state was an item already existed in the destination folder where the workflow was supposed to move the file to.

I tried lots of tricks to get the workflows to automatically start, I had about 250 instances of this happening and no scripts I found online would resolve this issue. They just wouldn’t cancel / resume.

In the end I removed the workflow from the list (which killed all instances) and then republished. Perfect. Now how to start them all again? Hmm

Well because these are #SharePoint2013 Workflows that run on a workflow management server, the normal scripts for starting them are different. To cut it short, use the following #script and all should be good.

$sourceWebURL = ‘http://YourURL
$sourceListName = ‘YourListName
$TargetWorkflow = ‘YourWorkflowName
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$items = $spSourceList.getItems()

# Getting a Workflow manager object to work with.
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
# Getting the subscriptions
$sub = $wfm.GetWorkflowSubscriptionService()
# Getting the specific workflow within the list of subscriptions on the specific list. (SP2010 associated workflows basically)
$WF = $sub.EnumerateSubscriptionsByList($spSourcelist.ID) | Where-Object {$_.Name -eq “$TargetWorkflow”}
# Getting a Workflow instance in order to perform my commands.
$wfis=$wfm.GetWorkflowInstanceService()

Foreach($item in $items){
# Creating the dictionary object I need to parse into StartWorkflow. This could be most other workflow commands.
$object = New-Object ‘system.collections.generic.dictionary[string,object]’
$object.Add(“WorkflowStart”, “StartWorkflow”);
$wfis.StartWorkflowOnListItem($WF, $item.ID, $object)
}

All you need to do is edit the BOLD text above and you should be on your way. Copy and Paste it into PowerShell ISE and save as PS1. Then run the file through the SharePoint 2013 Management Shell.

Good Luck!

SharePoint post!

All this talk about Confluence recently has really made me want to blog about SharePoint so I thought I would write about something that I have recently had to do. This was built within SharePoint 2013 and although it’s not really something great to some people, it has saved a lot of money within the company I work in and has made peoples lives easier for the tasks they are set to do.

I was tasked with replacing the manual post for a complete site (400 items per day) not very much but for a small site this is still quite a lot when you take into account the opening, checking, reading and actioning it.

I created a basic SharePoint team site within SharePoint 2013 and created a library for each area (7 in total) which all had unique permissions, locked down via Active Directory group embedded within a SharePoint group with custom permissions. The users can only open, edit meta data and view the libraries that they have permissions to view. No delete options! We don’t want someone getting the hump with a piece of post and deleting it because they don’t want to action it!

INFO: All of the post is delivered to our main sorting office and is opened, sorted and then put into a machine which scans the documents, converts them to PDF and sends them to SharePoint.

I created a library called “Drop Off” which is where all the items are sent to, during the send to SharePoint options the people in the sorting office can assign meta data to the documents which when doing in bulk really doesn’t take that much time.

Once the files hit the “Drop Off” area a custom workflow with “App Steps” run on each item and move to the relevant areas using the “Business Type” column I created.

If an items has been scanned incorrectly the users can just change the “Business Area” drop down menu and another custom workflow using “App Steps” will move to the correct area even if the user doesn’t have permissions to that folder.

By doing this I have ensured that all post is captured, none can go missing and no one can delete something. It also has full auditing on so managers can see who is doing what and how many items are currently completed, outstanding etc.

The completed items are then paused for 60 days before being deleted. During this time if someone needs to edit the meta data for this post the timer is restarted for another 60 days.

This isn’t on a big scale compared to one I built previously within SharePoint 2010, it’s built in the same way using “Impersonation Steps” and gets roughly about 1200 items of post each day. Yep that is a lot of storage in use to say an item of post can have 20 pages with a total PDF size of 40MB depending on the contents of the pages and the 60 day deletion limit.

So that is just a little something I have been working on recently, I will update more when I get some of my other projects completed and the outcome of them!