Wednesday, October 10, 2012

PowerShell 3 and SP2010, forever apart...?

It's well-documented that SP2010 is so hardcore about .Net 3.5 that it has a tattoo on its biceps of the build number in an XML element.

Of course, in my eagerness to adopt PowerShell and start to flex my muscles with it (which admittedly is rather tough to do when you don't have a sizeable farm to manage), I deployed PowerShell 3 on my development server, and now suddenly PowerShell doesn't like me anymore.

There's a small handful of posts out there (mostly related to PowerGUI) that essentially tell the story: PowerShell v3 doesn't play well with the SP2010 cmdlets (because they won't work with .Net 4.0). I tried to use a .config file for the PowerShell executeable to deny it access to .Net 4.0, but that simply didn't work as the PS engine requires 4.0. The common recommendation is to change the shortcuts for PowerShell on the upgraded servers to add "-version 2" to the launch command for PowerShell.

Well, that's great and all, but what about PS Remoting? Whenever I launch a local PS client and then remote into a server, the remote system is still running v3 (see $psversiontable), and I can't very well invoke a new instance of PowerShell from that remote session by trying the "powershell -version 2" trick from a remote session.

Luckily, PSv3 helps us out somewhat. First, we need to create a PSSessionConfigurationFile on the remote server:

New-PSSessionConfigurationFile -Path .\PowerShellv2.pssc

Now, open that file, and look for the line which contains the following:

The configuration name is up to you, I used it simply because there's an existing configuration entry for PSv3 named "Microsoft.PowerShell". You'll get a couple of confirmation prompts and the WinRM service will be restarted (make sure you're not kicking anyone out of the system!). Once this is done, from your client: