PowerShell Enable Versioning in all Site Collection Lists & Libraries

Often it’s a requirement to have Versioning turned on in a SharePoint List or Library. Versioning is a list/library level attribute and there’s unfortunately no way via the Site Settings GUI to tell SharePoint at the Site Collection or Site level to always have versioning turned on when a new list or library is created..

Traditionally, If you want versioning to be turned on in each new list/library, you’d have to either:

  • Use your own library template (with versioning turned on)
  • Use feature + event handler to programmatically activate versioning on each new list

The easiest way out of those two options is probably to use your own template. To do this, create a new document library, activate versioning, then save this list as template.

When you create a new list, you will then be able to use your template and directly create a list with versioning activated.

What about cases where we don’t want to/can’t use templates and we have admins spinning up new lists/libraries and jonesing for that versioning goodness?
The following PowerShell can be used to report on, and optionally enable Versioning on all Lists and Libraries in the site collection URL it is fed.
Minor Versioning, and Major/Minor Version quantity limit toggling is also in there but commented out. To turn on those options, simply remove the # symbol from the beginning of the lines.

PowerShell Script (save as file e.g. Enable-Versioning.ps1):

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = $args[0]
$execute = $args[1]
$site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
Write-Host "Inspecting " $web.Title
foreach ($list in $web.Lists) {
Write-Host "Versioning enabled: " $list.EnableVersioning
Write-Host "MinorVersioning Enabled: " $list.EnableMinorVersions
Write-Host "EnableModeration: " $list.EnableModeration
Write-Host "Major Versions: " $list.MajorVersionLimit
Write-Host "Minor Versions: " $list.MajorWithMinorVersionsLimit
if($execute -eq "execute") {
$list.EnableVersioning = $true
#if($list.BaseType -eq "DocumentLibrary") {
#$list.EnableMinorVersions = $true
#$list.MajorVersionLimit = 3
#$list.MajorWithMinorVersionsLimit = 3
Write-Host $list.Title " is updated"

Script takes two parameters:
1. Required: Site collection URL e.g. http://mysitecollection Specifies the site collection to operate on.
2. Optional: execute Script runs in report mode only unless you add the word execute
Example 1: Run the script in report mode only (no changes effected):
    c:usersadministratordesktop.Enable-Versioning.ps1 http://mysitecollection
Example 2: Run the script in execute mode:  c:usersadministratordesktop.Enable-Versioning.ps1 http://mysitecollection execute

This script could potentially be run on an automated basis via the Windows Task Scheduler – this would let you run it on a regular basis to ensure all lists/libraries in a site collection have Versioning turned on.


WireBear PDF DocIcon Solution

Use this solution to automatically include an icon for PDF documents in SharePoint 2010 (Foundation or Server). Here’s a longer introduction on Chris Kent’s blog: theChrisKent.com

Visit the Codeplex Page

What it Does:

This solution does 2 things:

-Installs an Icon file in your 14 Hive
-Adds a Mapping entry in the TEMPLATE/XML/DOCICON.xml file for PDF documents


Users of your sites can often be confused by the fact that PDF documents in Document Libraries have a simple white icon like any other unrecognized file. By using this solution, the standard PDF icon will be shown instead making your users feel safe and secure as if in the hands of a fuzzy, cuddly bear.

All of this can be done manually as recommended by Microsoft and Adobe. However, in the event of recovery or the addition of new servers to your farm these changes will have to be repeated manually. This is both irritating and error-prone. By deploying these changes through a solution you can be sure that:

-The changes will be reapplied in the event of Disaster Recovery
-The changes will be applied to new servers as they are added to your farm
-You don’t have to personally edit every 14 Hive for each server in your farm

How it Works:

A small icon file is deployed to the file system on each server and on activation a one-time timer job runs. This job checks the DOCICON.xml file on each server for a pdf mapping and if it doesn’t exist, it creates one pointing to the new icon.

An IIS reset is performed automatically as part of the deployment (If the server running Central Admin is also hosting the web applications, it may need to have IIS reset manually). Then any document libraries with PDF files will now have the familiar PDF icon next to them! WHOO WHOO!

On deactivation, the same timer job runs again but this time removes the pdf mapping entry.

The icon used comes from Adobe and can be found here: http://www.adobe.com/misc/linking.html

You don’t have Add and Customize Pages permissions required to perform this action

Steps to create the message “You don’t have Add and Customize Pages permissions required to perform this action”:

1. Make a new document library, set it the “Basic Page” template.
2. Assign a user Full Control on the document library
3. Have that user create a new document in the new document library.

>>> At this point you may receieve “Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. You don’t have Add and Customize Pages permissions required to perform this action.”

This causes a lot of confusion as applying “Full Control” on the document ibrary would seem to imply to the layman that the users in that group would be granted access accordingly. However it’s clearly not working for you at this point, so what’s the scoop on this? Turns out SharePoints famed “inverted NTFS Permission”-style permission hierarchy is not as clear cut as simply saying “SharePoint Permissions are granted in order most permissive first”.

At this point, a frustrated admin would start looking at the next possible permissions to fiddle with, in order to work around the seemingly odd error message:

1. Clearly taking the next step up of giving someone “Full Control” of the entire site (Site Actions > Site Permissions), would not be desirable in most cases.
2. Giving the user “Add and Customize Pages” permissions on the entire site would allow them to edit, but is also probably not desirable in most circumstances since they could also “Add, change or delete HTML pages or Web Part pages and edit the web site using designer.

The solution:
1. You must have “Add and Customize Pages” permission from the site level to perform this action, the permission is not in the list permission level.
2. Add a new permission level which only includes “Add and Customize Pages” permission, and then create a new SharePoint group with this permission level.
3. Add the users into the SharePoint group and these users will get the “Add and Customize Pages” permission from the site level (site permission).
4. To Add/Edit a page, the users would also need the permission level “Contributor” in the list permission level.

It’s important to note that when you grant the full control to the users in the list permission level, that the users won’t get the permission from the site level.