Tuesday 24 February 2015

Run reusable workflow for all list Items in SharePoint using PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
# URL of the Site
$web = Get-SPWeb -Identity https://sharepointsrv/site1
$manager = $web.Site.WorkFlowManager
# Name of the list
$list = $web.Lists["Shared Documents"]
# Name of the Workflow
$assoc = $list.WorkflowAssociations.GetAssociationByName("On Item Created","en-US")
$data = $assoc.AssociationData
$items = $list.Items
foreach($item in $items) {
        $wf = $manager.StartWorkFlow($item,$assoc,$data,$true)
}
$manager.Dispose()
$web.Dispose()

No comments:

Post a Comment