For Every Library in Every Site in Every Web do…

A big thank you to Get-SPScripts.com : PowerShell Scripts for SharePoint for putting me on the right track. I was able to copy most of the code right from his article.

PowerShell for setting the max limit on all libraries with versioning in all sites, on both of my web apps.

cls
$snapIn = Get-PSSnapin | where-object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}
if($snapIn -eq $null) {
 Add-PsSnapin Microsoft.SharePoint.PowerShell
}
$allWebApps = ("https://WEBAPP1.com", "https://WEBAPP2.com")
foreach ($siteUrl in $allWebApps)
{
 Write-Host "$siteUrl";
 $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl);
 $spWebApp = $rootSite.WebApplication;
foreach($SPSite in $spWebApp.Sites) 
 {
#Get site collection
 $site = Get-SPSite $SPSite
#Go through each site in the site collection
 $site | Get-SPWeb -limit all | ForEach-Object {
write-host "Checking site:"$_.Title
#Go through each document library in the site
 #Select if library has versioning
 $_.Lists | where { $_.EnableVersioning -eq $true } | ForEach-Object {
write-host "Library with Versioning:"$_.Title
#Make the list changes
 $_.MajorVersionLimit = 10
# If minor version enabled, limit them as well.
 if($_.EnableMinorVersions -eq $true){
 write-host "Library has minor versions"
 $_.MajorWithMinorVersionsLimit = 10
 }
#Update the list
 $_.Update()
 }
 }
 #Dispose of the site object
 $site.Dispose()
}
 $rootSite.Dispose();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: