使用2.0版本的运行时启动PowerShell ISE

10

当安装了PowerShell 3.0时,我可以强制PowerShell开始使用版本2.0。

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

这对于不支持 .Net Framework V 4(例如 SharePoint!)的 snapin 非常有用。

PowerShell ISE 有相应的替代品吗?

我尝试运行 powershell_ise.exe -version 2.0,但这并没有起作用。

运行 powershell_ise.exe -help 并没有显示任何能满足我的需求的参数。


我调整了这个文件,但是ISE似乎需要.Net V4,因为它在这个调整下崩溃了。 - Steve B
2个回答

9
调整配置文件没有用,powershell_ise.exe 绝对依赖于 .Net V4。它还严重依赖于 PowerShell 引擎的 V3 版本。
安装了 PowerShell V3 后,没有受支持的方法可以运行 PowerShell ISE 的 V2 版本。与核心 PowerShell 二进制文件(如 System.Management.Automation.dll)不同,我认为 V2 ISE 二进制文件是作为 V3 安装的一部分被覆盖或删除的。
恐怕您必须从 powershell.exe 运行脚本。

2

通过创建新的PSSession,您可以运行2.0 runtime命令。

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

如果您不退出PSSession,则可以从Powershell ISE 3中运行2.0运行时命令。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接