Forum Discussion

Audi86's avatar
Audi86
Brass Contributor
Jul 26, 2022

PowerShell to find all suspended workflow for classic SharePoint online sites

I have a powershell script to find the list for all suspended workflows in classic SP online site but i am getting error "Add-PsSnapin : No snap-ins have been registered for Windows PowerShell version 5".

On some research i found that this sript is for SP server

Can you please advise, how to modify it to use it with SP online. Thanks

 

if ( (Get-PSSnapin -Name "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.SharePoint.Powershell
}

$siteURL = "<Site URL>";
$libName = "<LibraryName>";

$spWeb = Get-SPWeb $siteURL;
$spList = $spWeb.Lists[$libName];
$spListItems = $spList.Items;

#Get the Workflow Manager object and then the instance of the Manager
$wfMgr = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spWeb);
$wfInstanceSvc = $wfMgr.GetWorkflowInstanceService();

foreach($spListItem in $spListItems)
{
    #Get a list of workflow instances running for the item in the library
    $wfInstances = $wfInstanceSvc.EnumerateInstancesForListItem($spList.ID, $spListItem.ID);
    
    foreach($wfInstance in $wfInstances)
    {
        #Check to see if the instance is suspended.  If so, write it.
        if($wfInstance.Status -eq "Suspended")
        {
            write-host("Instances for library item: {0}" -f $spListItem.ID);   
        }
    }
}

 

2 Replies

Resources