PowerShell Versioning

So, you’ve got your SharePoint 2010 development environment all setup nice and pretty – check.

You’ve gotten the hang of the PowerShell thing and it’s working all slick like – sweet.

Now you hear there’s a brand NEW version of PowerShell out there with even more fun toys and stuff.  So you download the latest and greatest (PowerShell version 3) and head home with the comforting thought that tomorrow’s gonna be a good day.

Now it’s first thing in the morning.  You fire up your development machine and kick off the SharePoint 2010 Management Shell and you see this…

The local farm is not accessible

Interesting.  Let’s do a quick check of the farm with a simple Get-SPFarm command…

Microsoft SharePoint is not supported.

What the?  Well, when you upgraded to PowerShell 3.0, you automatically upgraded the SharePoint 2010 Management Shell at the same time, and the new version is built for .NET Framework 4.0.  But as you know, the SharePoint 2010 object model won’t run in a .NET 4.0 AppDomain, which means you’d have to be running PowerShell 2.0 in order for any of the “SP” cmdlets to work.

Wonderful.

To see which version of PowerShell you’re running, just issue either the $host.Version or $PSVersionTable commands at the PS prompt.  The latter command also shows you the current CLR version, which is the crux of our current issue.

psversiontable

As you can see, we’re running PowerShell version 3.0, which has loaded the CLR version 4.0.30319.

Shortcut PropertiesSo what to do?  Easy.  Let’s modify the shortcut so that it automatically “down shifts” into PowerShell version 2.0 whenever we need to do our SharePoint work.  The rest of the time we’ll cruise along at a more reasonable warp.

From the START menu, right-click the “SharePoint 2010 Management Shell” shortcut and select properties.

Notice the highlighted bit where it says “-NoExit”.  What we need to do is add a switch to the PowerShell.exe command that tells PS to load version 2.0 instead of version 3.0.

…PowerShell.exe –Version 2.0 –NoExit…

Make this change and then click OK.

The next time you start up your management shell, you’ll see that all your SharePoint goodness is restored.  The world will start spinning again, and life will be good.

SharePointRestored

Enjoy.

3 comments

  1. John: thanks for this. SP2013 requires PS 3.0, but there seem to be some issues when using these two together, too. Do you have any words of wisdom on this? I’m trying to install SP2013 using the AutoSPInstaller scripts and running into some errors on a fresh server (Win2008 R2 SP1).

    1. Hi Milton,

      I ran into similar problems on W2K R2. Have you tried building out a fresh WIN 2012 server for your SP2013 development? Also, you might need to crack open the AutoSPInstallerFunctions.ps1 and look for places where it spawns a separate instance of PowerShell to ensure it is loading the correct version.

      Hope this helps,
      John

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.