if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
# 2 variables which need to be set
$siteCollection = "http://SharePoint/Sites/SiteCollection"
$documentRetentionCount=10
# get site collection
$site = new-object Microsoft.SharePoint.SPSite($siteCollection)
# loop through each subsite
foreach ($web in $site.AllWebs)
{
write-host $web.url
# loop through all lists in each subsite
foreach ($list in $web.Lists)
{
# examine if BaseType of list is a Document Library and if versioning is turned on
if (($list.BaseType -eq "DocumentLibrary") -and ($list.EnableVersioning))
{
# Set the Major version limit to keep the latest 10 versions
$list.MajorVersionLimit = $documentRetentionCount
$list.Update()
foreach($item in $list.Items)
{# Perform a system update on each item
$item.SystemUpdate($true)
}
}
}
}
$web.Dispose();
$site.Dispose();
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)