- PowerShellTab 对象The PowerShellTab Object
- 本文内容
- 方法Methods
- “属性”Properties
- AddOnsMenuAddOnsMenu
- CanInvokeCanInvoke
- ConsolepaneConsolepane
- DisplayNameDisplayName
- ExpandedScriptExpandedScript
- 文件Files
- 输出Output
- 提示Prompt
- ShowCommandsShowCommands
- StatusTextStatusText
- HorizontalAddOnToolsPaneOpenedHorizontalAddOnToolsPaneOpened
- VerticalAddOnToolsPaneOpenedVerticalAddOnToolsPaneOpened
- 另请参阅See Also
PowerShellTab 对象The PowerShellTab Object
本文内容
PowerShellTab 对象代表 Windows PowerShell 运行时环境。
方法Methods
调用(脚本)Invoke( Script )
在 Windows PowerShell ISE 2.0 和更高版本中受支持。
在 PowerShell 选项卡中运行给定的脚本。
备注
此方法仅适用于其他 PowerShell 选项卡,不适用于运行它的 PowerShell 选项卡。它不返回任何对象或值。如果代码修改任何变量,则这些更改将仍保存在根据其调用该命令的选项卡上。
Script - 要运行的脚本块的 System.Management.Automation.ScriptBlock 或字符串。
1. # Manually create a second PowerShell tab before running this script.
2. # Return to the first PowerShell tab and type the following command
3. $psISE.PowerShellTabs[1].Invoke({dir})
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 选项卡的运行时环境。
[millisecondsTimeout] - 可选整数,默认值为 500。如果在指定时间内未完成命令,则该命令将生成 TimeoutException 并显示消息“操作已超时。”
1. # Create a new PowerShell tab and then switch back to the first
2. $psISE.PowerShellTabs.Add()
3. $psISE.PowerShellTabs.SetSelectedPowerShellTab($psISE.PowerShellTabs[0])
5. # Invoke a simple command on the other tab, in its own scope
6. $psISE.PowerShellTabs[1].InvokeSynchronous('$x=1', $false)
7. # You can switch to the other tab and type '$x' to see that the value is saved there.
9. # This example sets a value in the other tab (in a different scope)
10. # and returns it through the pipeline to this tab to store in $a
11. $a = $psISE.PowerShellTabs[1].InvokeSynchronous('$z=3;$z')
12. $a
14. # This example runs a command that takes longer than the allowed timeout value
15. # and measures how long it runs so that you can see the impact
16. Measure-Command {$psISE.PowerShellTabs[1].InvokeSynchronous('sleep 10', $false, 5000)}
“属性”Properties
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. # Note the use of "_" as opposed to the "&" for mapping to the fast key letter for the menu item.
5. $menuAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('_Process', {Get-Process}, 'Alt+P')
6. # Add a nested menu.
7. $parentAdded = $psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add('Parent', $null, $null)
8. $parentAdded.SubMenus.Add('_Dir', {dir}, 'Alt+D')
9. # Show the Add-ons menu on the current PowerShell tab.
10. $psISE.CurrentPowerShellTab.AddOnsMenu
CanInvokeCanInvoke
在 Windows PowerShell ISE 2.0 和更高版本中受支持。
只读布尔属性,如果可以使用 Invoke( Script ) 方法调用脚本,则返回 $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.CanInvoke
9. $secondTab.Invoke({sleep 20})
10. $secondTab.CanInvoke
ConsolepaneConsolepane
在 Windows PowerShell ISE 3.0 和更高版本中受支持,但不存在于早期版本中。在 Windows PowerShell ISE 2.0 中,这命名为 CommandPane。
获取“控制台”窗格 editor 对象的只读属性。
1. # Gets the Console Pane editor.
2. $psISE.CurrentPowerShellTab.ConsolePane
DisplayNameDisplayName
在 Windows PowerShell ISE 2.0 和更高版本中受支持。
读写属性,可获取或设置 PowerShell 选项卡上显示的文本。默认情况下,选项卡命名为“PowerShell #”,其中 # 表示数字。
1. $newTab = $psISE.PowerShellTabs.Add()
2. # Change the DisplayName of the new PowerShell tab.
3. $newTab.DisplayName = 'Brand New 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 和更高版本中受支持。
只读属性,可获取 PowerShell 选项卡中打开的脚本文件集合。
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 对象用于相同的目的。
只读属性,可获取当前编辑器的“输出”窗格。
1. # Clears the text in the Output pane.
2. $psISE.CurrentPowerShellTab.output.clear()
提示Prompt
在 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 和更高版本中受支持,但不存在于早期版本中。
只读属性,指示水平“加载项”工具窗格当前是否打开。
1. # Gets the current state of the horizontal Add-ons tool pane.
2. $psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
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
