Tag: Windows PowerShell

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
$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()
if($execute -eq "execute") {
$list.EnableVersioning = $true
#if($list.BaseType -eq "DocumentLibrary") {
#$list.EnableMinorVersions = $true
#}
#$list.MajorVersionLimit = 3
#$list.MajorWithMinorVersionsLimit = 3
$list.Update()
Write-Host $list.Title " is updated"
}
}
}

Usage:
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.

 

PowerShell Intellisense-like Syntax Highlighting for Visual Studio 2012

Following up to my previous post which details the requirements to get PowerShell intellisense in Visual Studio 2010, here is the recipe for getting the same goodies in Visual Studio 2012:

PowerShell is an essential tool for advanced SharePoint development & administration. Unfortunately Visual Studio doesn’t offer PowerShell code syntax highlighting or Intellisense natively. You can however use Adam Driscoll’s plugin PowerGUI VSX from Codeplex, which runs on top of PowerGUI.

Note: Development seems to have stopped for a while on that project, not sure if it’s just super stable for 2012 and no updates have been required or what, but in any case, go to the Codeplex page and show some love to encourage further development.

PowerGUI V requires the free, standalone application PowerGUI. Please download the correct version:

Some useful sources for SharePoint PowerShell scripts and advice:
http://sharepointpsscripts.codeplex.com/releases/view/40582
http://powergui.org/servlet/KbServlet/download/2812-102-4534/SharePoint2010PowerShell.pdf
http://blog.falchionconsulting.com/

Windows PowerShell™ command-line interface is a new command-line tool and supporting scripting language from Microsoft that complements Cmd.exe in the Windows administration context. In the SharePoint administration context, Windows PowerShell supersedes the Stsadm.exe administration tool. Moving forward, you should use Windows PowerShell scripting technology to develop any new command-line scripts in SharePoint.

Concurrency Error with PSConfig

Patching SharePoint servers, you’ve probably run into the situation where you try to run PSConfig to upgrade a server and it fails on step three. Looking at the error logs, you’ll may see SPUpdatedConcurrencyException is the error that was thrown.

An exception of type Microsoft.SharePoint.Administration.SPUpdatedConcurrencyExc
eption was thrown.  Additional exception information: An update conflict has occ
urred, and you must re-try this action. The object SPUpgradeSession Name=Upgrade
-20120917-101200-949 was updated by MYDOMAINspinstall, in the PSCONFIG (3540) pr
ocess, on machine SERVER1.  View the tracing log for more information about the
 conflict.

Total number of configuration settings run: 3
Total number of successful configuration settings: 2
Total number of unsuccessful configuration settings: 1
Successfully stopped the configuration of SharePoint Products.
Configuration of SharePoint Products failed.  Configuration must be performed be
fore you use SharePoint Products.  For further details, see the diagnostic log l
ocated at C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14LOGSPSCDiagnostics_9_17_2012_10_11_55_375_12483735.log

..and the application
event log.

There are a lot of entries on the web about this – lots of information about clearing out the SharePoint object cache; but that may not always work. What I’ve found that seems to correct the problem every time is to run this command on the offending server:

1. Open Administrative Command Prompt
2. Go to

c:Program FilesCommonMicrosoft SharedWeb Server Extensions14BIN

3. Execute the following:

stsadm –o setproperty –propertyname command-line-upgrade-running –propertyvalue no

This should clear the “an upgrade is in process” flag on the server. You should now be able to run your PSConfig as expected.