次の方法で共有


PowerShellTab オブジェクト

PowerShellTab オブジェクトは、Windows PowerShell ランタイム環境を表します。

メソッド

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 タブでのみ機能します。 スクリプト ブロックが実行され、スクリプトから返されるすべての値が、コマンドを呼び出した実行環境に返されます。 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)}

プロパティ

AddOnsMenu

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 以降でサポートされています。

現在のプロンプト テキストを取得する読み取り専用プロパティ。 注: 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

VerticalAddOnToolsPaneOpened

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

関連項目

  • PowerShellTabCollection オブジェクト する
  • Windows PowerShell ISE スクリプト オブジェクト モデル の目的
  • ISE オブジェクト モデル階層 する