SharePoint Tech Blog


Set expiry policy on SharePoint list using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 1:51 pm

MOSS out of box functionaliy allows creating information management policies on lists to expire content on those lists. If this needs to be done using code then the following code could be used to set the expiry policy programmatically using PowerShell.
This code requires the SharePoint Powershell Profile to be loaded beforehand

#Include the additional dll references required
[Void] [System.Reflection.Assembly]::LoadWithPartialName("System")
[Void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Workflow")

$web=Get-SPWeb -webUrl "http://mossdev";




if ($policy -eq $null) {
$policy=[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]:: CreatePolicy($listctype,$null);

$policy.Description="Expire items the day after the expiry date";
$policy.Statement="Expire items the day after the expiry date";

if ($policy.Items.Count -ne 0)
foreach ($policyitem in $policy.Items)
if ($policyitem.Name -eq "Expiration")

if ($expirypolicyexists -eq $false)
#set the internal field name and workflow id according to your needs
#in this case it has been set to expire the item based on the
#expiry date custom field and execute the disposition approval workflow
#when the item expires
"Expiry policy added"
"An expiry policy already exists - not overwriting";




  1. Where do I get this library


    for use in PowerShell?

    Comment by David Hancock — 09/12/2010 @ 6:15 pm

    • If you use a Powershell Editor such as PowerGUI, you should get intellisense when you type in:


      … the rest should follow.

      Comment by kctnpblog — 17/03/2011 @ 10:42 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Create a free website or blog at

%d bloggers like this: