Enable Versions on every SharePoint Site with PowerShell (updated with logging)

The Script below will list the version status of every site in your farm.
Note that as the script is below, it only reports, you’ll need to uncomment 3 lines if you want it to make the changes.

It’s a good idea to run the script once or twice before you do that, so you have a log of what settings were.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$timestamp = get-date -format "yyyMMdd_hhmmtt"
$filenameprefix = "VersionScriptoutput"
$logfile = ("{0}_{1}.csv" -f $filenameprefix, $timestamp)

$header = "ListURL,Enabled"
$header | out-file -filepath $logfile

# tip - the script as is will pull every sharepoint site (at the IIS level) in your farm.
# if you want to filter this to a single IIS site,
# remove the # from the middle of the next line and enter your site's url

$iissitelist = get-spwebapplication # | where {$_.url -eq "https://www.yoursite.com/"}
foreach ($iissite in $iissitelist)
{
	foreach ($SiteCollection in $iissite.sites)
	{
		write-host $SiteCollection -foregroundcolor Blue
		foreach ($oneweb in $SiteCollection.allwebs)
		{
		   write-host $oneweb.url -foregroundcolor Green
		   #now this is is where we look at the lists
		   $lists = $oneweb.lists
		   foreach ($list in $lists)
		   {
			  if($list.EnableVersioning -eq $false)
			  {
				  write-host  "$($iissite.url)$oneweb/$list is a not using versions" -foregroundcolor yellow
				  $msg = "$($oneweb.url),$($list.rootfolder)"	
			      $msg | out-file -filepath $logfile -append
                    # note!
                    # if you actually want to make the changes, uncomment the next 3 lines!
				  #$list.Enableversioning = $true
				  #$List.MajorVersionLimit = 3
				  #$list.update()
			  }
			  else
			  {
				  Write-host  "$($oneweb.url)/$($list.RootFolder) has versions enabled! " -foregroundcolor green
				  $msg = "$($oneweb.url)/$($list.rootfolder),true"				  
                  $msg | out-file -filepath $logfile -append
			  }
		   } 
		}
	}
}

 

One thought on “Enable Versions on every SharePoint Site with PowerShell (updated with logging)

Leave a Reply