We are preparing to migrate content from a SharePoint 2007 environment to a SharePoint 2013 farm, by way of a third party tool.
As part of the pre migration cleanup, I've been looking at document versions across site collections. We have a large amount of document versions, some of which will not be required.
We are planning to only move the latest version of the documents over, but in some cases, we will need to keep the history of some of the documents. So we will need to pick and choose.
Where there are libraries that have a large number of document versions, I'd like to remove those now, while we analyse what is left over. I was hoping that the following script (from http://www.mukalian.com/blog/post/2011/04/10/PowerShell-Script-to-Delete-All-Versions-in-a-Document-Library.aspx) would be able to pick and chose a sub-site and delete just that site/libraries versions only - but it does it across an entire site collection.
Can anyone tell me if it's possible to modify this script, so that I can target it against a site/library, instead of a full site collection.
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# get site
$site = new-object Microsoft.SharePoint.SPSite("http://mossdev:8000")
# loop through webs
foreach ($web in $site.AllWebs)
{
# loop through all lists in web
foreach ($list in $web.Lists)
{
# examine if BaseType of list is NOT a Document Library
if ($list.BaseType -ne "DocumentLibrary")
{
# forget the rest and return to top
continue
}
# loop through each item
foreach ($item in $list.Items)
{
# work with the file object as we're in a document library
$file = $item.File
# delete all versions
$file.Versions.DeleteAll()
}
}
}
$web.Dispose();
$site.Dispose();
In the script above, I've modified the
$site = new-object Microsoft.SharePoint.SPSite("http://mossdev:8000")
so that it hit a particular site, for example:
http://example.com/sitecollection/site
But what it did was actually hit
http://example.com/sitecollection(getting rid of all versions across the collection).