NOTE: this post corrects the incorrect advice given out by Microsoft – read this before you try using any MS blogs to fix this issue.
I’m sure we’ve all come across this error once in a while when launching SharePoint 2010 Management Shell – mostly because (as security-conscious devs and admins) we’ve got UAC on and have not chosen to run the shell as an administrator. Then there’s the other reason, which is the lack of SharePoint_Shell_Access role assignment in SQL Server for the logged in user. These are both extensively documented on the internet, in places such as Bradley Schacht’s blog.
However, there is now a NEW cause of this error!
The cause is documented on this MS blog and is correct. However, the solution provided doesn’t work. When you put in the “-version 2” it should come before the -NoExit switch. i.e. the ‘Target’ property of the shortcut should read:
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Version 2 -NoExit " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "
If you try and use the Microsoft recommended solution you get an error saying “Ampersand not allowed. The & operator is reserved for future use;”. If you remove the ampersand you get the error “The term ‘-Version’ is not recognized as the name of a cmdlet[… etc.]”
I hope this post saves people a bit of time.