Enable/Disable versioning on ALL doc libs in web app via PowerShell

This works great. But be careful and use at your own risk. Always have a full backup and test in dev environment.

 

 

function Set-DocLibVersioning() {
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    foreach ($spService in $farm.Services) {
        if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
            continue;
       }

        foreach ($webApp in $spService.WebApplications) {
            if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }

            foreach ($site in $webApp.Sites) {
                foreach ($web in $site.AllWebs) {
                Write-Host "Site = " $site
                    foreach ($list in $web.Lists) {
                        if ($list.BaseType -eq "DocumentLibrary") {
                                Write-Host "List = " $list
                                # Enable Versioning
                                $list.EnableVersioning = $false
                                $list.Update()
                        }
                    }
                    $web.Dispose()
                }
                $site.Dispose()
            }
        }
    }
}
Set-DocLibVersioning

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