Powershell -version2 switch not working

Martin P 1 Reputation point
2021-01-05T15:52:05.607+00:00

Hello, I'm trying to run some Powershell scripts under version 2 for a Windows Server 2012 R2 that is hosting a SharePoint 2010 farm.

Things I've tried include:

  1. Changing the Powershell script path to the following: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2.0 -NoExit " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\sharepoint.ps1 ' "
  2. Inside the Powershell script console force the use of powershell 2 with: "powershell -version 2 .\my_script.ps1"

In both cases, running the scripts fails with it first saying that "the local farm is not accessible" and then saying "Restore-SPSite : Microsoft SharePoint is not supported with version 4.0.30319.42000 of the Microsoft .Net Runtime." when I try to run the first command.

The script has worked well for several years but a newer version of a backup software was recently installed that seems to have caused this change.

Is there a way to "force" the use of PS version 2?

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,955 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,547 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Sharath Kumar Aluri 3,071 Reputation points
    2021-01-05T16:09:10.007+00:00

    make sure your farm account has proper access.

    1. Click Start, and then right-click SharePoint 2010 Management Shell.
    2. Click Properties.
    3. Click the Shortcut tab in the SharePoint 2010 Management Shell Properties window.
    4. Input the following value in the Target field: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2.0 -NoExit " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\sharepoint.ps1 ' "

    If the above doesn't work, try the below one which worked all the time for me.

    #Open Powershell and run the below commands
    Start-Process cmd.exe -Credential "Domain\SP_Farm" -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs" 
    
    # And then enter in cmd.exe
    PowerShell -Version 2 #for SP 2010
    
    # Add the snapin now
    asnp *SharePoint*
    

    Thanks & Regards,


  2. Rich Matheisen 46,801 Reputation points
    2021-01-05T16:17:31.187+00:00

    It says that it's the version of .Net that isn't correct for the Restore-SPSite cmdlet, not the version of PowerShell.

    This might help: how-to-resolve-microsoft-sharepoint-is-not-supported-with-version-403031942000-of-the-microsoft


  3. Sharath Kumar Aluri 3,071 Reputation points
    2021-01-05T16:50:45.653+00:00

    seems like it's not the Version issue, The site you are restoring is not supported with your current SharePoint farm. either you might be using old one that will not support with your current SharePoint Farm or vice versa.

    Thanks & Regards,


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.