Sunday, June 16, 2013

Delete All Document Versions in SharePoint Document Library using PowerShell

Requirement is to : Delete all old document versions in SharePoint site collection to free-up some disk space occupied by document versions.

Here is the PowerShell script to delete all document versions in a site collection:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Site Collection
$site = Get-SPSite ""

#Loop through all sites in the site collection
foreach($web in $site.AllWebs)
  #Iterate through all Lists
  foreach($List in $Web.Lists)
 #Get only document libraries & Skip Hidden 
  if( ($List.BaseType -eq "DocumentLibrary") -and ($List.EnableVersioning) -and ($List.Hidden -eq $false) -and($List.IsApplicationList -eq $false) ) 
   #loop through each item
      foreach ($item in $list.Items)
    if($item.File.Versions.Count -gt 0)
        # delete all versions
     Write-Host "Deleting $($item.File.Versions.Count) Version(s) on: $($web.URL)$($item.URL)"
Write-Host "Script execution Completed!"
This PowerShell script will delete old versions in SharePoint document libraries for the entire site collection.

Related posts:
Checkout my codeplex tool to cleanup document versions in SharePoint: Download SharePoint Versioning Manager from CodePlex

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...