How to get the workflows associated with a specific list using PowerShell in SharePoint 2010


In this article we will be seeing how to get the workflows associated with a specific list using PowerShell in SharePoint 2010.

In this article

  • Get the workflows associated with a specific list using C#.
  • Get the workflows associated with a specific list using PowerShell.

    WorkFlow1.gif

Get the workflows associated with a specific list using C#

  • Open Visual Studio 2010.
  • Create Console Application.
  • Add the following Reference.
     
    • Microsoft.SharePoint.dll
       
  • Add the following Namespaces.
     
    • using Microsoft.SharePoint;
    • using Microsoft.SharePoint.Workflow;
  • Replace the code with the following.

class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://servername:1111/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPList list = web.Lists["Users"];                   
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPWorkflowAssociationCollection associationColl = list.WorkflowAssociations;
                    foreach (SPWorkflowAssociation association in associationColl)
                    {
                        Console.WriteLine(association.Name.ToString());
                    }
                    Console.ReadLine();
                }
            }
        }
    }


WorkFlow2.gif

Get the workflows associated with a specific list using PowerShell

$siteURL="http://serverName:1111/"
$listName="Users"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]
$wfManager=$site.WorkflowManager
$associationColl=$list.WorkflowAssociations
foreach($association in $associationColl)
{
write-host $association.Name
}
$web.Dispose()
$site.Dispose()

Up Next
    Ebook Download
    View all
    Learn
    View all