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,則會建立一個新的範圍來執行該指令。 它不會修改指令指定的 PowerShell 分頁的執行環境。 - [毫秒超時] - 預設為 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 分頁的 Add-ons 選單出現。
# 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 及更新版本。
# 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。
只讀屬性,能取得 Console 窗 格編輯器 物件。
# 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 中,但在後續版本的 ISE 中被移除或重新命名。 在後期版本的 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