How to invoke executable or powershell script from SharePoint 2010 Workflow?

10,294

Solution 1

You can use custom workflow action e.g.

http://ilovesharepoint.codeplex.com/wikipage?title=Execute%20PowerShell%20Script%20Action

Solution 2

This can be done without third-party software/plugins.

Create tasks queues. Queues are just SharePoint lists. Name each according to the job it's responsible for (e.g. "Purge Logs Queue"). Add columns to the queue to represent the appropriate task parameters. Add a Status column.

Create a workflow in Designer responsible for populating the queue.

For each queue create a PowerShell script that processes it and manages the Status. This is similar to what 2013 SharePoint workflows do with stages. The only difference is our scripts can be made to resume on the next go if a stage fails to complete.

Consider the fact that an individual item on the queue might fail to process. Adapt your script to continue processing the queue (if sensible) on any pass to avoid having one item block all progress.

Schedule these scripts to poll on an interval using some mechanism.

While you are still using SharePoint designer workflows to initiate things, handing off the work to PowerShell makes automating moderately complex tasks easier.

Share:
10,294
Ninja Cowgirl
Author by

Ninja Cowgirl

Updated on August 01, 2022

Comments

  • Ninja Cowgirl
    Ninja Cowgirl over 1 year

    I would like to invoke an executable (or Powershell script) from SharePoint 2010 workflow. What are my options? Is it even possible? I did some search online but nothing good comes out. All I get how to execute workflow from powershell script or executable but that's not what I am looking for.

    Idea is to when a approver done with approving a document (doc, docx, xls, or xlsx) then I would like workflow to invoke a powershell or executable with parameters.

    When I manually use the executable it looks like below from cmdlet.

    C:\ConvertDocs> .\convert.exe c:\docs\test.xls c:\pdfs\test.pdf
    

    I have a powershell with parameters that uses the same executable. And powershell script cmdlet look like below.

    .\call_Convert.ps1 c:\docs\test.xls c:\pdfs\test2.pdf