I was setting up a SharePoint Foundation Server 2010 SP2 site for a client which the OS it was running on was Windows Server 2012 R2. Now the installation, setting up the sites, and etc went fine. Until I started setting up Powershell scripts with a combination of BAT files and Task Scheduler tasks to run them (I’m a bit old school :P). At first the Task Scheduler task would run them but they would complete too quickly and there were no results from the Powershell scripts. I decided to open up a Powershell console and run the Powershell script themselves. When I tried running the PowerShell script, I got this nice error.
There is an easy fix to this but let me explain the problem first. With Windows Server 2012 R2, the PowerShell version is at 4.0 (This applies to Windows Server 2008 R2 as well if you installed PowerShell Version 3.0). PowerShell 4.0 uses MS .NET Framework version 4 to run things. With SharePoint Server 2010, this is still running in MS .Net Framework version 2.0. If you try to run SharePoint PowerShell scripts by loading the SharePoint Server 2010 Snap ins with a PowerShell 4.0 Console, you will get the error that I got.
But here is a simple fix! What you need to do is to run the PowerShell Console in version 2.0. In the example below, I use a BAT file to start a PowerShell Console and run my SharePoint PowerShell script.
All you need to do is to have that Parameter -version 2.0 when running powershell.exe
powershell.exe -version 2.0
After I made those adjustments in my BAT files, my SharePoint PowerShell scripts ran with no problems. You will not see this issue with SharePoint Server 2013.
I hope this has been useful for all of you!