PowerShellTab 对象The PowerShellTab Object

调用(脚本)Invoke( Script )

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

在 PowerShell 选项卡中运行给定的脚本。

备注

此方法仅适用于其他 PowerShell 选项卡,不适用于运行它的 PowerShell 选项卡。它不返回任何对象或值。如果代码修改任何变量,则这些更改将仍保存在根据其调用该命令的选项卡上。

Script - 要运行的脚本块的 System.Management.Automation.ScriptBlock 或字符串。

InvokeSynchronous( Script, [useNewScope], millisecondsTimeout )InvokeSynchronous( Script, [useNewScope], millisecondsTimeout )

在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。

在 PowerShell 选项卡中运行给定的脚本。

备注

此方法仅适用于其他 PowerShell 选项卡,不适用于运行它的 PowerShell 选项卡。运行脚本块,并且从该脚本返回的任何值将返回到从中调用该命令的运行环境。如果此命令采用更长时间才能运行比millesecondsTimeout的值指定,则该命令将失败并出现异常:运算超时。

Script - 要运行的脚本块的 System.Management.Automation.ScriptBlock 或字符串。

[useNewScope] - 可选的布尔值,默认值为 $true,如果设置为 $true,则会新建作用域以在其中运行命令。它不会修改该命令指定的 PowerShell 选项卡的运行时环境。

  1. $psISE.PowerShellTabs.Add()
  2. $psISE.PowerShellTabs.SetSelectedPowerShellTab($psISE.PowerShellTabs[0])
  3. # Invoke a simple command on the other tab, in its own scope
  4. $psISE.PowerShellTabs[1].InvokeSynchronous('$x=1', $false)
  5. # You can switch to the other tab and type '$x' to see that the value is saved there.
  6. # This example sets a value in the other tab (in a different scope)
  7. # and returns it through the pipeline to this tab to store in $a
  8. $a = $psISE.PowerShellTabs[1].InvokeSynchronous('$z=3;$z')
  9. $a
  10. # This example runs a command that takes longer than the allowed timeout value
  11. # and measures how long it runs so that you can see the impact
  12. Measure-Command {$psISE.PowerShellTabs[1].InvokeSynchronous('sleep 10', $false, 5000)}

AddOnsMenuAddOnsMenu

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取 PowerShell 选项卡的“加载项”菜单。

  1. # Clear the Add-ons menu if one exists.
  2. $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear()
  3. # Create an AddOns menu with an accessor.
  4. $menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('_Process', {Get-Process}, 'Alt+P')
  5. # Add a nested menu.
  6. $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('Parent', $null, $null)
  7. $parentAdded.SubMenus.Add('_Dir', {dir}, 'Alt+D')
  8. # Show the Add-ons menu on the current PowerShell tab.
  9. $psISE.CurrentPowerShellTab.AddOnsMenu

CanInvokeCanInvoke

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读布尔属性,如果可以使用 方法调用脚本,则返回 $true 值。

  1. # CanInvoke will be false if the PowerShell
  2. # tab is running a script that takes a while, and you
  3. # check its properties from another PowerShell tab. It is
  4. # always false if checked on the current PowerShell tab.
  5. # Manually create a second PowerShell tab before running this script.
  6. # Return to the first tab and type
  7. $secondTab = $psISE.PowerShellTabs[1]
  8. $secondTab.Invoke({sleep 20})
  9. $secondTab.CanInvoke

在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。在 Windows PowerShell ISE 2.0 中,这命名为 CommandPane

获取“控制台”窗格 editor 对象的只读属性。

DisplayNameDisplayName

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

读写属性,可获取或设置 PowerShell 选项卡上显示的文本。默认情况下,选项卡命名为“PowerShell #”,其中 # 表示数字。

  1. $newTab = $psISE.PowerShellTabs.Add()
  2. # Change the DisplayName of the new PowerShell tab.

ExpandedScriptExpandedScript

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

读写布尔属性,可确定“脚本”窗格是展开还是隐藏的。

  1. # Toggle the expanded script property to see its effect.
  2. $psISE.CurrentPowerShellTab.ExpandedScript = !$psISE.CurrentPowerShellTab.ExpandedScript

文件Files

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

  1. $newFile = $psISE.CurrentPowerShellTab.Files.Add()
  2. $newFile.Editor.Text = "a`r`nb"
  3. # Gets the line count
  4. $newFile.Editor.LineCount

输出Output

此功能存在于 Windows PowerShell ISE 2.0 中,但已在更高版本的 ISE 中删除或重命名。在更高版本的 Windows PowerShell ISE 中,你可以将 ConsolePane 对象用于相同的目的。

只读属性,可获取当前的“输出”窗格。

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取当前提示文本。注意:Prompt 函数可以被用户的配置文件覆盖。如果结果不止一个简单的字符串,则此属性不会返回任何内容。

  1. # Gets the current prompt text.
  2. $psISE.CurrentPowerShellTab.Prompt

ShowCommandsShowCommands

在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。

读写属性,指示当前是否显示“命令”窗格。

  1. # Gets the current status of the Commands pane and stores it in the $a variable
  2. $a = $psISE.CurrentPowerShellTab.ShowCommands
  3. # if $a is $false, then turn the Commands pane on by changing the value to $true
  4. if (!$a) {$psISE.CurrentPowerShellTab.ShowCommands = $true}

StatusTextStatusText

在 Windows PowerShell ISE 2.0 和更高版本中受支持。

只读属性,可获取 PowerShellTab 状态文本。

  1. # Gets the current status text,
  2. $psISE.CurrentPowerShellTab.StatusText

HorizontalAddOnToolsPaneOpenedHorizontalAddOnToolsPaneOpened

在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。

只读属性,指示水平“加载项”工具窗格当前是否打开。

VerticalAddOnToolsPaneOpenedVerticalAddOnToolsPaneOpened

在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。

  1. # Turns on the Commands pane
  2. $psISE.CurrentPowerShellTab.ShowCommands = $true
  3. # Gets the current state of the vertical Add-ons tool pane.
  4. $psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened