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の任意の整数。 - コマンドが指定された時間内に完了しない場合、「The operation has timed out.」というメッセージを含む 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タブのAddonsメニューを表示できる読み取り専用プロパティです。
# 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と名付けられました。
Console Pane エディタ オブジェクトを取得する読み取り専用プロパティです。
# 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'
拡張スクリプト
Windows PowerShell ISE 2.0以降でサポートされています。
Script paneが拡張されているか非表示かを決定する読み書きブール属性です。
# Toggle the expanded script property to see its effect.
$psISE.CurrentPowerShellTab.ExpandedScript = !$psISE.CurrentPowerShellTab.ExpandedScript
Files
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
ショーコマンド
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}
ステータステキスト
Windows PowerShell ISE 2.0以降でサポートされています。
PowerShellTabの状態テキストを取得する読み取り専用プロパティです。
# Gets the current status text,
$psISE.CurrentPowerShellTab.StatusText
HorizontalAddOnToolsPaneOpened(横付けアドオンツール)PaneOpened(横付けアドオンツール)PaneOpened(横付けアドオンツール)
Windows PowerShell ISE 3.0以降でサポートされており、以前のバージョンには含まれていません。
水平の Add-Ons ツールパンが現在開いているかどうかを示す読み取り専用のプロパティです。
# Gets the current state of the horizontal Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
VerticalAddOnToolsPaneOpened(垂直アドオンツール)PaneOpened(垂直アドオンツール)パネル
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