This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So about a week ago I posted this, asking for help with versioning control on a site-wide level, along with clearing out all the versions PAST the max version set.
I wrote a handy piece of code that will help anyone with the same problem. (Sorry if it is shit, or ill-formatted etc)
cls
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#$allsite = get-spsite -limit all
#foreach ($sites in $allsite)
#{
"start WorkingSiteName" "_" (Get-Date -format "yyyy-MMM-dd HH:mm:ss").tostring() | out-file -FilePath c:\time.log -append
Send-MailMessage -To "[email protected]" -Subject "Scanning Started for company site" -From "[email protected]" -SmtpServer "smtpgateway company settings" -BodyAsHtml
$site = new-object Microsoft.SharePoint.SPSite("http://yoursite.com/subsite")
foreach ($web in $site.allwebs)
{
write-host $web.url
# loop through all lists in web
foreach ($list in $web.Lists)
{
# $list | select Rootfolder, Title , basetype, enableversioning, listitementitytypefullname, MajorVersionLimit, MajorWithMinorVersionsLimit #| export-csv C:\alldocumentlibrary.csv -Append -NoTypeInformation
# examine if BaseType of list is NOT a Document Library
if (($list.BaseType -eq "DocumentLibrary") -and ($list.EnableVersioning))# -and ($list.title -eq "Infrastructure Folder"))
{
# Keep latest 9 versions Plus current 1 Equal to 10
#$list.Title
#$list.basetype
#$list.enableversioning
#$list.listitementitytypefullname
#$list.MajorVersionLimit
$list.MajorVersionLimit = 9
$list.Update()
foreach($item in $list.Items)
{
$item.DisplayName
#$item.file.MajorVersion
$item.SystemUpdate() #this is super important get rid of all versions past 9
}
}
}
}
#}
#$web.Dispose();
#$site.Dispose();
"end WorkingSiteName" "_" (Get-Date -format "yyyy-MMM-dd HH:mm:ss").tostring() | out-file -FilePath c:\time.log -append
Send-MailMessage -To "[email protected]" -Subject "Scanning ended for company site" -From "[email protected]" -SmtpServer "smtpgateway company settings" -BodyAsHtml
Run this in powershell and it should rummage through all your contents, set the max version history to 9 (including current copy, equaling 10), and remove anything past that.
It will also write you a log for when it starts and stops found on C:/drive. AND send an email when it starts and stops. I wrote this in because I ran this script over the weekend, and wanted to keep an eye on it without worrying. Might also be handy to record pre and post storage size, as it eliminated quite a lot for us.
Subreddit
Post Details
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/sharepoint/...