次の方法で共有


SharePoint 2010 PowerShell incompatibility with .NET 4.X

There is a known compatibility issue with SharePoint 2010 and Windows Management Framework 4.0 (WMF), which also includes PowerShell 3.0. If you install these components on a server that also runs SharePoint 2010, you may encounter errors when running SharePoint PowerShell cmdlets:

PS C:\> Add-PSSnapin Microsoft.SharePoint.PowerShell
The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

PS C:\> Get-SPEnterpriseSearchServiceApplication
Get-SPEnterpriseSearchServiceApplication : Microsoft SharePoint is not supported with version 4.0.30319.1008 of the Microsoft .Net Runtime.

Although this is not a supported configuration, there is a workaround to force PowerShell 2.0 documented in KB 2796733 - SharePoint 2010 Management Shell does not load with Windows PowerShell 3.0

What isn't mentioned in the KB article is a different combination when this issue can occur, even if WMF 4.0 isn't installed. If your PowerShell version is 2.0 but configured to run with .NET 4.x CLR, you will still see the errors.

The $PSVersionTable will show the version of PowerShell and .NET that is being used. If it shows a CLRVersion of 4.x, you will probably still have problems running SharePoint 2010 cmdlets:

PS C:\> $PSVersionTable

Name Value
---- -----
PSVersion 2.0
CLRVersion 4.0.30319.1008

You can override the .NET CLR version with these steps:

  1. Create or edit a file at $pshome\powershell.exe.config

    1. If you use the ISE, also do the same for powershell_ise.exe.config
  2. Insert or edit the contents so that the line for the v2.x supportedRuntime is listed before the v4.x line.

    <?xml version="1.0"?>
    <configuration>
       <startup useLegacyV2RuntimeActivationPolicy="true">
         <supportedRuntime version="v2.0.50727"/>
         <supportedRuntime version="v4.0.30319"/>
     </startup>
    </configuration>

  3. Save the file and reopen any previous PowerShell sessions

  4. Test by adding the SharePoint snap-in, and running some SharePoint cmdlets, e.g.

    Add-PSSnapin Microsoft.SharePoint.PowerShell

This is similar to the procedure described in this post, but with forcing .NET version 2.x instead of version 4.x.

If this helps you, or if you still encounter these issues when running SharePoint 2010 PowerShell cmdlets, please post a comment or send me an e-mail.

Comments

  • Anonymous
    March 28, 2014
    This does not work on Win Server 2008 R2 after the changes are made for both PS and ISE, the program just force closes
  • Anonymous
    April 23, 2014
    Same as Mike, both PS and ISE just force close.
  • Anonymous
    May 01, 2014
    Same as Mike & Charles. I notice our comments are all recent, so MS must have pushed new out a KB that is compounding the problem (seeing as Alex's workaround was successful for all prior 2014). I see a lot of KB's installed on my server 3/12/2014 & 4/9/2014.
  • Anonymous
    May 28, 2014
    Seems like the file on Server 2008 is Powershell.exe.activation_config. It's located at C:Program Files(x86)Common FilesNetApp.

    Hope this helps!
  • Anonymous
    June 18, 2014
    I am pretty certain I tested this workaround without the SP2010 SP2 slipstream install. According to KB2724471, SharePoint 2010 should be compatible with Windows Server 2012 and 2012R2. They list the management shell errors under the resolved issues, but I haven't tested yet. See: http://support.microsoft.com/kb/2724471/en-us
  • Anonymous
    November 03, 2014
    BIG-THX@Mike Porter
    Seems the NetApp Sharepoint Backup Software reconfigures the powershell... After adding the missing to C:Program Files(x86)Common FilesNetAppPowershell.exe.activation_config it is working.
  • Anonymous
    March 09, 2015
    The comment has been removed
  • Anonymous
    July 08, 2015
    +1 for Mike Porter

    Seems like the file on Server 2008 is Powershell.exe.activation_config. It's located at C:Program Files(x86)Common FilesNetApp.
  • Anonymous
    July 31, 2015
    Huge thanks. Worked perfectly.
  • Anonymous
    February 24, 2016
    HAving the same problem as DHood82. Configuration the CLR with .config does not work. CLR 4 is always choosen. Even on Windows Server 2008 R2. Any help?