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:
Here is the PowerShell script to delete all document versions in a site collection:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue#Get the Site Collection#Loop through all sites in the site collectionforeach($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)" $item.file.Versions.DeleteAll() } } } } } $site.Dispose()Write-Host "Script execution Completed!" |
Reference:
http://www.sharepointdiary.com/2013/06/delete-all-document-versions-using-powershell.html
No comments:
Post a Comment