Running SharePoint List Workflows using PowerShell on all List Items
Too often it is required to execute
workflows on multiple list items and there is no OOTB feature available in
SharePoint to achieve this objective. One such example is to update all list
items, delete multiple list items based on a criteria set in Workflow etc.
Below Power Shell script will
help you to run List Workflow on all list items in one go.
# URL of the Site in red
color
$web = Get-SPWeb -Identity
"http://localhost/"
$manager =
$web.Site.WorkFlowManager
# Name of the list in red
color
$list = $web.Lists["WorkflowTest"]
# Name of the Workflow in
red color
$assoc =
$list.WorkflowAssociations.GetAssociationByName("Reminder","en-US")
$data =
$assoc.AssociationData
$items = $list.Items
foreach($item in $items)
{
$wf =
$manager.StartWorkFlow($item,$assoc,$data,$true)
}
$manager.Dispose()
$web.Dispose()
#
Copy the script save it
anywhere in your machine such as C Drive with extension .ps1.
Run the SharePoint
Management Shell as “Run As Administrator”.
Type & “path where .ps1
is saved”.
And here we go.
Good Luck.
No comments:
Post a Comment