Bulk provisioning SharePoint 2010 document retention policies using PowerShell

2010, as well as MOSS, allows you to set up document retention policies on items within a document library.
You can choose what action you want to take in regards to a particular instance of a content type in the library, say document.
When you like to implement same document retention policy for entire site or a web and each document library within it – PowerShell is much more efficient .paring to performing this configuration manually.

In this article, I would like to demonstrate how you can add a new retention policy to a Shared Documents library within my site http://intranet.contoso...
The formula will move documents older than 1 year to a Recycle Bin.

1. Create new text file on your development machine and place the following code in it:

$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];
$list = $web.Lists["Shared Documents"];

2. Save the file with ps1 extension and run the script as shown below.

As a result your retention formula will be created in Shared Documents library as follows.

The script is pretty self explanatory, I’m sure you will agree. One reference I would like to point out is additional Actions you can take in regards to documents. In our case we just moved the item to recycle big by using this action ID: Microsoft.Office.RecordsManagement.tramadol no prescription.Expiration.Action.MoveToRecycleBin
but if you’d like to see what else is available, here is the list :
For more PowerShell automation goodness, you might like to check out my book
Enjoy!

About the author: Yaroslav Pentsarskyy