1

I have enabled 10 major versions on all document libraries in my farm using the code below but I now need to exclude a few specific sites so that the major version number can be different to 10.

How would I go about adding that to this code?

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = $args[0]
$site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
  Write-Host "Inspecting " $web.Title
  foreach ($list in $web.Lists) {
    if($list.BaseType -eq "DocumentLibrary") {
      Write-Host "Versioning enabled: " $list.EnableVersioning
      $host.UI.WriteLine()
      #Write-Host "MinorVersioning Enabled: " $list.EnableMinorVersions
      #$host.UI.WriteLine()
      #Write-Host "EnableModeration: " $list.EnableModeration
      #$host.UI.WriteLine()
      Write-Host "Major Versions: " $list.MajorVersionLimit
      $host.UI.WriteLine()
      #Write-Host "Minor Versions: " $list.MajorWithMinorVersionsLimit
      #$host.UI.WriteLine()
      $list.EnableVersioning = $true
      #Disable creation of minor (draft) versions (document libraries only)
      $list.EnableMinorVersions = $false
      $list.MajorVersionLimit = 10
      #$list.MajorWithMinorVersionsLimit = 5
      $list.Update()
      Write-Host $list.Title " is updated with MajorVersionLimit 10 "
  }
 }
}
5

I asume you are filtering by site and not by library.

You could do something like this:

$ignoreSites = @("http://siteurl/site1", "http://siteurl/site2")

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = $args[0]
$site = Get-SPSite($siteURL)
$webs = $site.AllWebs | ? {$_.Url -notin $ignoreSites}
foreach($web in $webs) {
 Write-Host "Inspecting " $web.Title
 foreach ($list in $web.Lists) {
 if($list.BaseType -eq "DocumentLibrary") {
 Write-Host "Versioning enabled: " $list.EnableVersioning
 $host.UI.WriteLine()
    #Write-Host "MinorVersioning Enabled: " $list.EnableMinorVersions
    #$host.UI.WriteLine()
    #Write-Host "EnableModeration: " $list.EnableModeration
    #$host.UI.WriteLine()
 Write-Host "Major Versions: " $list.MajorVersionLimit
 $host.UI.WriteLine()
    #Write-Host "Minor Versions: " $list.MajorWithMinorVersionsLimit
    #$host.UI.WriteLine()
 $list.EnableVersioning = $true
    #Disable creation of minor (draft) versions (document libraries only)
 $list.EnableMinorVersions = $false
 $list.MajorVersionLimit = 10
    #$list.MajorWithMinorVersionsLimit = 5
 $list.Update()
 Write-Host $list.Title " is updated with MajorVersionLimit 10 "
 }
 }
}

So you basically just filter the $site.AllWebs property.

It might be necessary to change -notin keyword to -notcontains (-notin seems to be available from PowerShell 3.0 on).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.