Close

Information Risk Management: 

Microsoft Office 365, Microsoft Teams, Microsoft SharePoint Server, Microsoft SharePoint Online, Microsoft Exchange Online, Azure DevOps & App Services, Azure Machine Learning

PowerShell Versioning

John Holliday

March 4, 2013

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.
Table of Content

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.

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on print