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…
Interesting. Let’s do a quick check of the farm with a simple Get-SPFarm command…
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.
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.
As you can see, we’re running PowerShell version 3.0, which has loaded the CLR version 4.0.30319.
So 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.