PowerShell控制台和PowerShell ISE之间的区别

21

PowerShell控制台和PowerShell ISE的区别是什么?我在PowerShell配置文件的上下文中提出这个问题。因为PowerShell控制台和PowerShell ISE都有不同的配置文件。

1个回答

14

来自ISE和PowerShell控制台之间的区别

  1. 交互式控制台应用程序支持有限,尝试使用cmd.exe,然后尝试使用cmd.exe /k

    a) cmd.exe /c dir仍然有效,并且更多信息可在此处找到:http://blogs.msdn.com/powershell/archive/2009/02/04/console-application-non-support-in-the-ise.aspx

  2. 控制台应用程序输出不带颜色

  3. 默认为STA

    a) 尝试 $host.Runspace.ApartmentState

    b) PowerShell默认为MTA(ApartmentState显示为Unknown),但可以使用powershell -sta启动为sta模式。

    c) ISE始终为STA

  4. 不支持[Console]类,尝试[console] :: BackgroundColor ='white'。

    a) 一般而言,脚本应使用主机API(例如write-host)而不是[Console]类,以便它们适用于控制台、ISE、远程和其他shell。

  5. $host.UI.RawUI的支持极其有限(接近零)。我们只支持颜色和标题

    a) 最好在$psISE.Options中设置颜色,因为您可以将其设置为任何颜色,而不仅仅是控制台颜色

  6. 自定义/简单翻页。请参阅gc函数:more

    a) ISE没有分页器

  7. Start-Transcript在ISE中无效

  8. 一些线程区域差异

    a) 如果您所在的地区不支持控制台(例如阿拉伯文),则ISE将获取ar-sa作为Get-Culture,而powershell.exe将fallback为en-us或其他值。

  9. 建议在ISE中无效

    a) 例如,在"C:\Program Files\Internet Explorer"中执行iexplore.exe

    b) 只有在PowerShell.exe中才会看到以下建议[3,常规]:找不到命令iexplore.exe,但当前位置确实存在。默认情况下,Windows PowerShell不会从当前位置加载命令。如果您信任此命令,请输入“. \ iexplore.exe”。

     

    有关更多详细信息,请参见“get-help about_Command_Precedence”。

  10. ISE运行不同的配置文件

       

    a) ISE配置文件位于Microsoft.PowerShellISE_profile.ps1,而powershell位于Microsoft.PowerShell_profile.ps1中

      

    b) http://msdn.microsoft.com/en-us/library/bb613488(VS. 85).aspx

     

    c)   http://www.leeholmes.com/blog/TheStoryBehindTheNamingAndLocationOfPowerShellProfiles.aspx

     

    d) 您可以使用存储在$profile.CurrentUserAllHosts中的常规配置文件,使其在两个shell中运行

  11. 只有ISE具有$psISE

  12. a)it可以访问http://psisecream.codeplex.com/http://blogs.msdn.com/powershell/archive/2008/12/29/powershell-ise-can-do-a-lot-more-than-you-think.aspx


3
实际上,PowerShell控制台在V3和V4中已经恢复默认使用STA(单线程单元)了。唯一使用MTA(多线程单元)的版本是V2。值得一提的是,包括Visual Studio内的ISE和NuGet在内,每个主机都有自己的配置文件脚本,为用户提供进行特定于主机的初始化和配置的机会。profile.ps1文件对所有主机都是全局的。尝试执行$profile | fl -Force - Keith Hill

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