Banner Advert
Chris Wright
Posted on September 7, 2012 by
Leave a comment

Despite the title of this blog post the goal is not to hit the most buzz words. The goal is to help you with something many SharePoint end users face – keeping SharePoint content current. Does any of this sound familiar?


Users keep draft documents on to their MySite and leave it there indefinitely even though they don’t need the draft?

Users drop multiple versions of the document into a library instead of editing one document?


One of the ways to help users keep their content current and erase irrelevant files is to enable expiration driven workflow on certain “high risk” libraries such as Shared Documents or Personal Documents on MySites.For example: once the uploaded document has been sitting around for more than say 100 days … you trigger a workflow which allows the user to retain the content or delete it; or at least this is my technical assumption.


If that sounds like something you’d like to do, here is the PowerShell way of getting there. Remember, in order for you to be able to set Information Management Policies on libraries you need to enable the following site feature:


Enable-SPFeature -Identity "063C26FA-3CCC-4180-8A84-B6F98E991DF3" -Url [Site Collection Url] -force


First we get a hold of out library and associate Disposition Approval workflow to it.


$SiteUrl = "http://mysite/personal/administrator"

$NewSite = Get-SPSite | Where-Object {$_.Url -eq $SiteUrl}

$RootWeb = $NewSite.RootWeb

$sharedDocs = $RootWeb.Lists["Shared Documents"];

$libraryPolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.ListPolicySettings]($sharedDocs)

$workflowTemplates = $RootWeb.WorkflowTemplates;

$workflowTemplate = $workflowTemplates.GetTemplateByBaseID([System.Guid]"dd19a800-37c1-43c0-816d-f8eb5f4a4145");

if ($workflowTemplate -ne $null)

{

$RootWeb.Lists.Add("WorkflowTasks", "WorkflowTasks", [Microsoft.SharePoint.SPListTemplateType]::Tasks);

$RootWeb.Lists.Add("WorkflowHistory", "WorkflowHistory", [Microsoft.SharePoint.SPListTemplateType]::WorkflowHistory);

$taskList = $RootWeb.Lists["WorkflowTasks"];

$historyList = $RootWeb.Lists["WorkflowHistory"];

$workflowAssociation = $sharedDocs.WorkflowAssociations.GetAssociationByName("DispositionReminder",[System.Globalization.CultureInfo]::InvariantCulture);

if ($workflowAssociation -eq $null)

{

$workflowAssociation = [Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($workflowTemplate, "DispositionReminder", $taskList, $historyList);

$sharedDocs.WorkflowAssociations.Add($workflowAssociation);

}

}


Now that the disposition approval workflow is associated to the library, we can enable our retention policy to trigger the above workflow after 100 days. Below code has to be added right after to run as one script.



if ($libraryPolicy.ListHasPolicy -eq 0)
{
$libraryPolicy.UseListPolicy = $true

$libraryPolicy.Update()

}

$contentType = $sharedDocs.ContentTypes["Document"]

[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::CreatePolicy($contentType, $null)

$newPolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($contentType)

$newPolicy.Items.Add("Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration",

'<Schedules nextStageId="1" default="false">'+

'<Schedule type="Default">'+

'<stages>'+

'<data stageId="1">'+

'<formula id="Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn">'+

'<number>100</number>'+

'<property>Created</property>'+

'<propertyId>8c06beca-0777-48f7-91c7-6da68bc07b69</propertyId>'+

'<period>days</period>'+

'</formula>'+

'<action type="workflow" id="'+ $sharedDocs.WorkflowAssociations.GetAssociationByName("DispositionReminder", [System.Globalization.CultureInfo]::InvariantCulture).Id +

'"/>'+

'</data>'+

'</stages>'+

'</Schedule>'+

'</Schedules>');

$newPolicy.Update()

$sharedDocs.Update()


That’s it; you can also automate this script to run on all of your My Sites or other site collections and on specific libraries. The result: once the content has reached 100 days after it has been created, the author will receive an email asking them to either delete or leave the content as-is. As a second retention stage you might want to consider recycling the content after say 150 days.



This article was originally posted here, on the ShareMuch blog.

No comments yet, why not be the first?

Add a comment