locked
How do I bulk delete versions in Sharepoint 2003? RRS feed

  • Question

  •  I am working on a migration and came across several files with thousands of versions and I want to delete all versions of files.  We turned off versioning but the versions are still there.   This is a VERY large document library with thousands of files in there.   Each one with dozens of files and some with thousands of versions. 
    Friday, December 21, 2012 5:14 PM

Answers

  • PowerShell is most often used to cleanup versions. There are a number of sample available on the web:

    http://www.bing.com/search?q=sharepoint+delete+versions+powershell

    Of course, do some testing in a development or staging environmen t first.


    Mike Smith TechTrainingNotes.blogspot.com my SP customization book

    Wednesday, December 26, 2012 5:36 PM
  • Are you double hopping from SP2003 to SP2010?  I don't recall any STSADM commands for deleting versions in SP2003 (am checking though) but if these items are migrated to SharePoint 2010, than the following script (sourced from here) should work: -

    snap = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
    if ($snap -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.Powershell
    }
    #Set site url ‘http://<servername>/site’. ‘sps2010’ is my test sharepoint server
    $siteurl = “http://sps2010/test”
    #Document Library Name. ‘VersionsTestDL’ is my test document library
    $dlname = "VersionsTestDL"
    
    #get site obj
    $site=new-object Microsoft.SharePoint.SPSite($siteurl)
    #open root web
    $web = $site.OpenWeb()
    #get doclib
    $dl = $web.Lists[$dlname]
    
    foreach ($doc in $dl.Items)
    {
      #Delete All Versions
      $versions = [Microsoft.SharePoint.SPListItemVersionCollection]$doc.Versions
      $versions.DeleteAll()
      #If you want to move them to Recycle Bin only  and not to delete them forever, use RecycleAll() method 
    
    }
    $dl.Update()
    
    $web.dispose()
    $site.dispose()


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/


    Thursday, December 27, 2012 12:30 PM
    Answerer

All replies

  • PowerShell is most often used to cleanup versions. There are a number of sample available on the web:

    http://www.bing.com/search?q=sharepoint+delete+versions+powershell

    Of course, do some testing in a development or staging environmen t first.


    Mike Smith TechTrainingNotes.blogspot.com my SP customization book

    Wednesday, December 26, 2012 5:36 PM
  • Are you double hopping from SP2003 to SP2010?  I don't recall any STSADM commands for deleting versions in SP2003 (am checking though) but if these items are migrated to SharePoint 2010, than the following script (sourced from here) should work: -

    snap = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
    if ($snap -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.Powershell
    }
    #Set site url ‘http://<servername>/site’. ‘sps2010’ is my test sharepoint server
    $siteurl = “http://sps2010/test”
    #Document Library Name. ‘VersionsTestDL’ is my test document library
    $dlname = "VersionsTestDL"
    
    #get site obj
    $site=new-object Microsoft.SharePoint.SPSite($siteurl)
    #open root web
    $web = $site.OpenWeb()
    #get doclib
    $dl = $web.Lists[$dlname]
    
    foreach ($doc in $dl.Items)
    {
      #Delete All Versions
      $versions = [Microsoft.SharePoint.SPListItemVersionCollection]$doc.Versions
      $versions.DeleteAll()
      #If you want to move them to Recycle Bin only  and not to delete them forever, use RecycleAll() method 
    
    }
    $dl.Update()
    
    $web.dispose()
    $site.dispose()


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/


    Thursday, December 27, 2012 12:30 PM
    Answerer