Forum Discussion
Fromelard
Aug 08, 2017Steel Contributor
PowerShell script to configure the List versionning before execute the migration to SP Online
When you are in a migration project from SharePoint On Premise to SharePoint Online, the worst case is the SPList in which is the User decided to implement versionning without any limitation.
You can have thousand of versions to migrate into only one list which will require many hours to migrate, generally without any added value for the Users because they never realized that setting was set.
The Migration does not like that because it will be so long to execute that site migration.
In my case, i have a site in which the size used by with only 2 items (execl file less than 1MB) of one list was more than 400MB.
So that first will delete all the versions before the XX last ones:
function Delete-Version-History([string]$SPWebURL, [string]$SPListName, [int]$MaintainVersionNumber)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $nullWrite-Host " -------------------------------------------------------- "
Write-Host "SPWeb URL to configure:", $SPWebURL -foregroundcolor Red
$site = new-object Microsoft.SharePoint.SPSite($SPWebURL)
$web = $site.openweb()
Write-Host " >> SPWeb URL from Object:", $web.URL -foregroundcolor Green$SPlist = $web.Lists[$SPListName]
Write-Host " >> SPList to Configure:", $SPlist.Title -foregroundcolor Green
Write-Host " >> Total Item to check:", $SPlist.Items.Count -foregroundcolor Greenforeach ($SPitem in $SPlist.Items)
{
Write-Host " >>>>>> File Item:", $SPitem.Name, "- Version Total:", $SPItem.Versions.count -foregroundcolor Magenta
$currentVersionsCount = $SPItem.Versions.count
if($currentVersionsCount -gt $MaintainVersionNumber)
{
for($i=$currentVersionsCount-1; $i -gt $MaintainVersionNumber; $i--)
{
$SPItem.versions[$i].delete()
Write-Host " >>>>>> Version:", $i, " Deleted"$SPlist.Update();
}
}
}
$web.Dispose();
$site.Dispose();}
cls
Delete-Version-History http://MyWebApplication/sites/MySPSite/MySPWeb "My List Name" 50
This case is cool, but sometime, it could be better to directly apply the Versionning and force the list to apply this settings immediatly, so that other script will be used to:
function Configure-Versionning-SPList([string]$SPWebURL, [string]$SPListName, [int]$MaintainMajorVersionNumber, [bool]$EnableMinorVersionYesNo, [int]$MaintainMinorVersionNumber)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $nullWrite-Host " -------------------------------------------------------- "
Write-Host "SPWeb URL to configure:", $SPWebURL -foregroundcolor Red
$site = new-object Microsoft.SharePoint.SPSite($SPWebURL)
$web = $site.openweb()
Write-Host " >> SPWeb URL from Object:", $web.URL -foregroundcolor Green$SPlist = $web.Lists[$SPListName]
Write-Host " >> SPList to Configure:", $SPlist.Title -foregroundcolor Green
if($SPlist.EnableVersioning -eq $true)
{
$SPlist.MajorVersionLimit = $MaintainMajorVersionNumber;
if($EnableMinorVersionYesNo -eq $true)
{
$SPlist.EnableMinorVersions = $EnableMinorVersionYesNo
$SPlist.MajorWithMinorVersionsLimit = $MaintainMinorVersionNumber;
}
}
else
{
$SPlist.EnableVersioning = $True
$SPlist.MajorVersionLimit = $MaintainMajorVersionNumber;
if($EnableMinorVersionYesNo -eq $true)
{
$SPlist.EnableMinorVersions = $EnableMinorVersionYesNo
$SPlist.MajorWithMinorVersionsLimit = $MaintainMinorVersionNumber;
}
}
$SPlist.Update();
$web.Dispose();
$site.Dispose();
}function Force-Apply-Versionning-OnItems([string]$SPWebURL, [string]$SPListName, [int]$MaintainVersionNumber)
{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $nullWrite-Host " -------------------------------------------------------- "
Write-Host "SPWeb URL to configure:", $SPWebURL -foregroundcolor Red
$site = new-object Microsoft.SharePoint.SPSite($SPWebURL)
$web = $site.openweb()
Write-Host " >> SPWeb URL from Object:", $web.URL -foregroundcolor Green$SPlist = $web.Lists[$SPListName]
Write-Host " >> SPList to Configure:", $SPlist.Title -foregroundcolor Green
Write-Host " >> Total Item to check:", $SPlist.Items.Count -foregroundcolor Greenforeach ($SPitem in $SPlist.Items)
{
Write-Host " >>>>>> File Item:", $SPitem.Name, "- Version Total:", $SPItem.Versions.count -foregroundcolor Magenta
$currentVersionsCount = $SPItem.Versions.count
if($currentVersionsCount -gt $MaintainVersionNumber)
{
$SPitem.SystemUpdate()
}
}
$SPlist.Update();
$web.Dispose();
$site.Dispose();}
Configure-Versionning-SPList http://MyWebApplication/sites/MySPSite/MySPWeb "My List Name" 50 $false 0
Force-Apply-Versionning-OnItems http://MyWebApplication/sites/MySPSite/MySPWeb "My List Name" 50
Any choice you selected, the only objective is to reduce as much as possible the time required to migrate the content.
Romelard Fabrice [MVP]
Source:
- http://salaudeen.blogspot.co.uk/2011/01/limitcleanup-versioning-in-sharepoint.html
- https://social.technet.microsoft.com/Forums/ie/en-US/53694860-2a7c-4bfb-ba1f-3b8b17c031b9/sharepoint-2007-document-library-deleting-all-versions-in-bulk?forum=sharepointadminlegacy
- http://crashcarr.com/22/22
- http://www.sharepointdiary.com/2011/01/limit-versioning-and-delete-old-versions-in-sharepoint.html#ixzz4pAZ0epuO
French version:
No RepliesBe the first to reply