[玩转系统] PowerShellTab 对象
作者:精品下载站 日期:2024-12-14 02:59:26 浏览:14 分类:玩电脑
PowerShellTab 对象
PowerShellTab 对象代表 Windows PowerShell 运行时环境。
方法
调用(脚本)
在 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( 脚本, [useNewScope], millisecondsTimeout )
在 Windows PowerShell ISE 3.0 及更高版本中受支持,但在早期版本中不存在。
在 PowerShell 选项卡中运行给定脚本。
笔记
此方法仅适用于其他 PowerShell 选项卡,不适用于运行该方法的 PowerShell 选项卡。脚本块将运行,并且从脚本返回的任何值都将返回到您调用命令的运行环境。如果该命令的运行时间比 millesecondsTimeout 值指定的时间长,则该命令将失败并出现异常:“操作已超时”。
脚本 - System.Management.Automation.ScriptBlock 或 String 要运行的脚本块。
[useNewScope] - 可选布尔值,默认为 $true
如果设置为 $true
,则会创建一个新作用域,在其中运行命令。它不会修改命令指定的 PowerShell 选项卡的运行时环境。
[millisecondsTimeout] - 可选整数,默认为500。如果该命令未在指定时间内完成,则该命令会生成 TimeoutException 并显示消息“操作已超时”。
# 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
CanInvoke
在 Windows PowerShell ISE 2.0 及更高版本中受支持。
如果可以使用 Invoke( Script ) 方法调用脚本,则返回 $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 is
# 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
ConsolePane
在 Windows PowerShell ISE 3.0 及更高版本中受支持,但在早期版本中不存在。在 Windows PowerShell ISE 2.0 中,它被命名为 CommandPane。
获取控制台窗格编辑器对象的只读属性。
# Gets the Console Pane editor.
$psISE.CurrentPowerShellTab.ConsolePane
DisplayName
在 Windows PowerShell ISE 2.0 及更高版本中受支持。
读写属性,用于获取或设置 PowerShell 选项卡上显示的文本。默认情况下,选项卡命名为“PowerShell #”,其中 # 代表数字。
$newTab = $psISE.PowerShellTabs.Add()
# Change the DisplayName of the new PowerShell tab.
$newTab.DisplayName = 'Brand New Tab'
ExpandedScript
在 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 中,但在更高版本的 ISE 中被删除或重命名。在 Windows PowerShell ISE 的更高版本中,您可以使用 ConsolePane 对象来实现相同目的。
获取当前编辑器的输出窗格的只读属性。
# Clears the text in the Output pane.
$psISE.CurrentPowerShellTab.output.clear()
迅速的
在 Windows PowerShell ISE 2.0 及更高版本中受支持。
获取当前提示文本的只读属性。注意:提示功能可以被用户的配置文件覆盖。如果结果不是简单字符串,则此属性不返回任何内容。
# 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
水平附加工具窗格已打开
在 Windows PowerShell ISE 3.0 及更高版本中受支持,但在早期版本中不存在。
只读属性,指示水平附加组件工具窗格当前是否打开。
# Gets the current state of the horizontal Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
垂直附加工具窗格已打开
在 Windows PowerShell ISE 3.0 及更高版本中受支持,但在早期版本中不存在。
只读属性,指示垂直附加组件工具窗格当前是否打开。
# Turns on the Commands pane
$psISE.CurrentPowerShellTab.ShowCommands = $true
# Gets the current state of the vertical Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
参见
- PowerShellTabCollection 对象
- Windows PowerShell ISE 脚本对象模型的用途
- ISE 对象模型层次结构
- 上一篇:[玩转系统] 其他有用的脚本对象
- 下一篇:[精彩网文] 什么被认为是上层中产阶级?
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag