Today I already explained how to clone a SharePoint list using a SharePoint power shell script. I used this script to create archive lists.
Now I want to create a workflow to archive items after a certain time period. This is what I did:
In my case I want to move the items to the archive after 2 years.
Configure the workflow to start automatically when an item is created.
To start the workflow for existing items, I also used the following SharePoint power shell script:
# get web $web = Get-SPWeb http://yoursite # get list $list = $web.Lists["Your list"] # get workflow assiciation $wa = $list.WorkflowAssociations.GetAssociationByName("Archive", [System.Globalization.CultureInfo]::CurrentCulture); # start the workflow for each item ForEach($i in $($list.Items)){ $web.Site.WorkflowManager.StartWorkflow($i, $wa, $wa.AssociationData, [Microsoft.SharePoint.Workflow.SPWorkflowRunOptions]::Synchronous) }
# get web $web = Get-SPWeb http://yoursite # get list $list = $web.Lists["Your list"] # get workflow assiciation $wa = $list.WorkflowAssociations.GetAssociationByName("Archive", [System.Globalization.CultureInfo]::CurrentCulture); # start the workflow for each item ForEach($i in $($list.Items)){ $web.Site.WorkflowManager.StartWorkflow($i, $wa, $wa.AssociationData, [Microsoft.SharePoint.Workflow.SPWorkflowRunOptions]::Synchronous) }