Sharepoint 2013 - Enable versioning with exception for all documents libraries

Andy PANYANOUVATH 1 Reputation point
2020-09-02T12:25:18.503+00:00

Hello,

I have a script which enable/update all document library on a web app in SharePoint 2013 :

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

Write-Host "Starting to update lists and Libraries"

$webs = get-spsite -limit all | get-spweb -Limit All
foreach ($web in $webs)
{
Write-Host "Updating Site" $web -foregroundcolor Black -backgroundcolor Yellow
foreach ($list in $web.lists)
{
Write-Host "Looking at list $list"

if ($list.BaseType -eq "DocumentLibrary" -and $list.BaseTemplate -eq "DocumentLibrary")
{
Write-Host "Updating list $list" -foregroundcolor Black -backgroundcolor Green
$list.EnableVersioning = $true;
$list.EnableMinorVersions = $false;
$list.EnableModeration = $false;
$list.MajorVersionLimit = 10;
$list.ForceCheckout = $false;
$list.Update()
}
}
$web.Dispose()
}
Write-Host "Done updating lists!" -foregroundcolor Black -backgroundcolor Green

I would like to add an exception : if there is already versioning enabled on a site, I don't want any update on it.
Is that possible ?

Thank you very much for your help.

Best regards,

Andy

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points
    2020-09-02T15:02:59.797+00:00

    Wouldn't you just add that to your 'if'?

    if ($list.BaseType -eq "DocumentLibrary" -and $list.BaseTemplate -eq "DocumentLibrary" -and $list.EnableVersioning -eq $false)