Use PowerShell to Check SharePoint Library Version History

Randomly ran across a library that a user had jacked versioning up to 99 versions.

So, how do you audit every list and library in a web app / site collection / site.

In the script below, I set the write-host to only be triggered if major or minor versions is greater than 20.

$siteURL = "http://webapp1.sharepointed.com/"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites)
{
	foreach($s in $site.AllWebs)
	{
		foreach($l in $s.lists)
		{
			$maj = $l.MajorVersionLimit
			$majMinor = $l.MajorWithMinorVersionsLimit
			
			if(($maj -gt 20) -or ($majMinor -gt 20))
			{
				Write-Host $s.Url
				Write-Host $l.Title
				Write-Host "Major: " $maj
				Write-Host "Minor: " $majMinor
			}
		}
	$s.Dispose()
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *