PowerShellTab 对象表示 Windows PowerShell 运行时环境。
Methods
Invoke( Script )
支持Windows PowerShell ISE 2.0及更高版本。
在PowerShell标签页中运行给定的脚本。
注释
这种方法只适用于其他 PowerShell 标签页,不适用于运行它的 PowerShell 标签页。 它不会返回任何对象或值。 如果代码修改了任何变量,那么这些更改会持续存在命令调用的标签页上。
- 脚本 - System.Management.Automation.ScriptBlock 或 String - 运行的脚本块。
# Manually create a second PowerShell tab before running this script.
# Return to the first PowerShell tab and type the following command
$psISE.PowerShellTabs[1].Invoke({dir})
InvokeSynchronous( Script, [useNewScope], millisecondsTimeout )
Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。
在PowerShell标签页中运行给定的脚本。
注释
这种方法只适用于其他 PowerShell 标签页,不适用于运行它的 PowerShell 标签页。 脚本块被执行,脚本返回的任何值都会返回到你调用命令的运行环境。 如果命令运行时间超过 千秒超时 值,则命令失败,并有例外:“作已超时。”
- 脚本 - System.Management.Automation.ScriptBlock 或 String - 运行的脚本块。
-
[useNewScope] - 默认为
$true可选布尔值 - 如果设置为$true,则创建一个新的 scope,在该范围内运行该命令。 它不会修改命令指定的PowerShell标签页的运行环境。 - [毫秒超时] - 默认为 500的可选整数。 - 如果命令在规定时间内未完成,则生成一个超 时异常 ,提示“作已超时。”
# Create a new PowerShell tab and then switch back to the first
$psISE.PowerShellTabs.Add()
$psISE.PowerShellTabs.SetSelectedPowerShellTab($psISE.PowerShellTabs[0])
# Invoke a simple command on the other tab, in its own scope
$psISE.PowerShellTabs[1].InvokeSynchronous('$x=1', $false)
# You can switch to the other tab and type '$x' to see that the value is saved there.
# This example sets a value in the other tab (in a different scope)
# and returns it through the pipeline to this tab to store in $a
$a = $psISE.PowerShellTabs[1].InvokeSynchronous('$z=3;$z')
$a
# This example runs a command that takes longer than the allowed timeout value
# and measures how long it runs so that you can see the impact
Measure-Command {$psISE.PowerShellTabs[1].InvokeSynchronous('sleep 10', $false, 5000)}
属性
附加菜单
支持Windows PowerShell ISE 2.0及更高版本。
只读属性,能获得PowerShell标签页的附加元件菜单。
# Clear the Add-ons menu if one exists.
$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Clear()
# Create an AddOns menu with an accessor.
# Note the use of "_" as opposed to the "&" for mapping to the fast key letter for the menu item.
$menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('_Process',
{Get-Process}, 'Alt+P')
# Add a nested menu.
$parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('Parent', $null, $null)
$parentAdded.SubMenus.Add('_Dir', {dir}, 'Alt+D')
# Show the Add-ons menu on the current PowerShell tab.
$psISE.CurrentPowerShellTab.AddOnsMenu
可呼唤
支持Windows PowerShell ISE 2.0及更高版本。
只读布尔属性,如果脚本可以用 $true 方法调用,则返回值。
# CanInvoke will be false if the PowerShell
# tab is running a script that takes a while, and you
# check its properties from another PowerShell tab. It's
# always false if checked on the current PowerShell tab.
# Manually create a second PowerShell tab before running this script.
# Return to the first tab and type
$secondTab = $psISE.PowerShellTabs[1]
$secondTab.CanInvoke
$secondTab.Invoke({sleep 20})
$secondTab.CanInvoke
控制台面板
Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。 在 Windows PowerShell ISE 2.0 中,这个系统被称为 CommandPane。
只读属性,获得控制台窗 格编辑器 对象。
# Gets the Console Pane editor.
$psISE.CurrentPowerShellTab.ConsolePane
显示名称
支持Windows PowerShell ISE 2.0及更高版本。
读取-写入属性,用来获取或设置显示在PowerShell标签页上的文本。默认情况下,标签页命名为“PowerShell #”,其中 # 代表数字。
$newTab = $psISE.PowerShellTabs.Add()
# Change the DisplayName of the new PowerShell tab.
$newTab.DisplayName = 'Brand New Tab'
扩展脚本
支持Windows PowerShell ISE 2.0及更高版本。
决定脚本面板是扩展还是隐藏的读写布尔属性。
# Toggle the expanded script property to see its effect.
$psISE.CurrentPowerShellTab.ExpandedScript = !$psISE.CurrentPowerShellTab.ExpandedScript
文件存储
支持Windows PowerShell ISE 2.0及更高版本。
只读属性,获取PowerShell标签页中打开的 脚本文件集合 。
$newFile = $psISE.CurrentPowerShellTab.Files.Add()
$newFile.Editor.Text = "a`r`nb"
# Gets the line count
$newFile.Editor.LineCount
输出
该功能存在于 Windows PowerShell ISE 2.0 中,但在后续版本中被移除或重命名。 在后续版本的Windows PowerShell ISE中,你可以使用 ConsolePane 对象实现同样的目的。
只读属性,获得当前 编辑器的输出面板。
# Clears the text in the Output pane.
$psISE.CurrentPowerShellTab.Output.Clear()
Prompt
支持Windows PowerShell ISE 2.0及更高版本。
只读属性,获取当前提示文本。 注意:该 prompt 功能可以被用户配置文件覆盖。 如果结果不是简单字符串,那么该性质不返回任何东西。
# Gets the current prompt text.
$psISE.CurrentPowerShellTab.Prompt
ShowCommands
Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。
读取-写入属性,指示命令面板当前是否显示。
# Gets the current status of the Commands pane and stores it in the $a variable
$a = $psISE.CurrentPowerShellTab.ShowCommands
# if $a is $false, then turn the Commands pane on by changing the value to $true
if (!$a) {$psISE.CurrentPowerShellTab.ShowCommands = $true}
StatusText
支持Windows PowerShell ISE 2.0及更高版本。
只读属性,获取 PowerShellTab 状态文本。
# Gets the current status text,
$psISE.CurrentPowerShellTab.StatusText
HorizontalAddOnToolsPaneOpened(横向附加工具面板已打开)
Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。
只读属性,表示水平 Add-Ons 工具窗是否当前打开。
# Gets the current state of the horizontal Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
垂直附加工具窗格已打开
Windows PowerShell ISE 3.0及以后版本支持,早期版本中不支持。
只读属性,表示垂直 Add-Ons 工具窗是否当前打开。
# Turns on the Commands pane
$psISE.CurrentPowerShellTab.ShowCommands = $true
# Gets the current state of the vertical Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened