Start PowerShell ISE with the 2.0 runtime

2019-04-06 06:13发布

问题:

When PowerShell 3.0 is installed, I can force PowerShell to start using the version 2.0

-Version
    Starts the specified version of Windows PowerShell.
    Enter a version number with the parameter, such as "-version 2.0"

This is useful with snapin that does not supports the .Net Framework V 4 (SharePoint!).

Is there an equivalent for PowerShell ISE ?

I tried to run powershell_ise.exe -version 2.0 but this does not works.

Running powershell_ise.exe -help does not show any parameter that could satisfy my needs.

回答1:

Tweaking the config file won't help, powershell_ise.exe definitely depends on .Net V4. It also depends heavily on the V3 version of the PowerShell engine.

There is no supported way to run V2 of the PowerShell ISE after PowerShell V3 is installed. Unlike the core PowerShell binaries (like System.Management.Automation.dll) I think the V2 ISE binaries are either overwritten or removed as part of the V3 installation.

I'm afraid you'll have to run your script from powershell.exe.



回答2:

You can run 2.0 runtime command by creating new PSSession.

Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 –ShowSecurityDescriptorUI

# Please consult system admin when your run set-item and Enable-WSManCredSSP command
Set-Item wsman:localhost\client\trustedhosts -value * -Confirm:$false -Force
Enable-WSManCredSSP -Role Client –DelegateComputer * -Force
Enable-WSManCredSSP -Role Server -Force

# For test purpose
# Get-WSManCredSSP
# get-item wsman:localhost\client\trustedhosts

$cred = Get-Credential
$session = New-PSSession -ComputerName $env:COMPUTERNAME -authentication credssp -ConfigurationName PS2 -Credential $cred
Enter-PSSession $session

# 2.0 runtime
Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb http://SPSite/
$web.Url

Exit-PSSession

Unregister-PSSessionConfiguration -Name PS2

Disable-WSManCredSSP -Role Client
Disable-WSManCredSSP -Role Server

If you don't exit PSSession, you can run 2.0 runtime command from Powershell ISE 3.