Obiekt PowerShellTab

Obiekt PowerShellTab reprezentuje środowisko uruchomieniowe programu Windows PowerShell.

Metody

Invoke( Skrypt )

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Uruchamia dany skrypt na karcie programu PowerShell.

Uwaga

Ta metoda działa tylko na innych kartach programu PowerShell, a nie na karcie programu PowerShell, z której jest uruchamiana. Nie zwraca żadnych obiektów ani wartości. Jeśli kod modyfikuje dowolną zmienną, zmiany te są utrwalane na karcie, na której wywoływano polecenie.

Script — System.Management.Automation.ScriptBlock lub String Blok skryptu do uruchomienia.

# 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], milisekundsTimeout )

Obsługiwane w programie Windows PowerShell ISE 3.0 lub nowszym i nie są obecne we wcześniejszych wersjach.

Uruchamia dany skrypt na karcie programu PowerShell.

Uwaga

Ta metoda działa tylko na innych kartach programu PowerShell, a nie na karcie programu PowerShell, z której jest uruchamiana. Blok skryptu jest uruchamiany, a każda wartość zwrócona ze skryptu jest zwracana do środowiska uruchamiania, z którego wywołano polecenie. Jeśli uruchomienie polecenia trwa dłużej niż określono wartość millesecondsTimeout , polecenie kończy się niepowodzeniem z wyjątkiem: "Upłynął limit czasu operacji".

Script — System.Management.Automation.ScriptBlock lub String Blok skryptu do uruchomienia.

[useNewScope] — Opcjonalna wartość logiczna, która jest domyślnie ustawiona na $true$truewartość , zostanie utworzony nowy zakres, w którym ma zostać uruchomione polecenie. Nie modyfikuje środowiska uruchomieniowego karty programu PowerShell określonej przez polecenie .

[milisekundyTimeout] — Opcjonalna liczba całkowita, która domyślnie ma wartość 500. Jeśli polecenie nie zostanie zakończone w określonym czasie, polecenie wygeneruje wyjątek TimeoutException z komunikatem "Upłynął limit czasu operacji".

# 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)}

Właściwości

AddOnsMenu

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość tylko do odczytu, która pobiera menu Dodatki dla karty programu 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

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość logiczna tylko do odczytu, która zwraca $true wartość, jeśli można wywołać skrypt za pomocą metody Invoke( Script ).

# 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

Okienko konsoli

Obsługiwane w programie Windows PowerShell ISE 3.0 lub nowszym i nie są obecne we wcześniejszych wersjach. W programie Windows PowerShell ISE 2.0 ta nazwa miała nazwę CommandPane.

Właściwość tylko do odczytu, która pobiera obiekt edytora okienka konsoli.

# Gets the Console Pane editor.
$psISE.CurrentPowerShellTab.ConsolePane

DisplayName

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość read-write, która pobiera lub ustawia tekst wyświetlany na karcie programu PowerShell. Domyślnie karty mają nazwę "PowerShell #", gdzie # reprezentuje liczbę.

$newTab = $psISE.PowerShellTabs.Add()
# Change the DisplayName of the new PowerShell tab.
$newTab.DisplayName = 'Brand New Tab'

ExpandedScript

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość logiczna odczytu i zapisu określająca, czy okienko Skrypt jest rozwinięte, czy ukryte.

# Toggle the expanded script property to see its effect.
$psISE.CurrentPowerShellTab.ExpandedScript = !$psISE.CurrentPowerShellTab.ExpandedScript

Pliki

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość tylko do odczytu, która pobiera kolekcję plików skryptów otwartych na karcie programu PowerShell.

$newFile = $psISE.CurrentPowerShellTab.Files.Add()
$newFile.Editor.Text = "a`r`nb"
# Gets the line count
$newFile.Editor.LineCount

Wyjście

Ta funkcja jest obecna w programie Windows PowerShell ISE 2.0, ale została usunięta lub zmieniona w nowszych wersjach środowiska ISE. W nowszych wersjach środowiska Windows PowerShell ISE można użyć obiektu ConsolePane w tym samym celu.

Właściwość tylko do odczytu, która pobiera okienko Dane wyjściowe bieżącego edytora.

# Clears the text in the Output pane.
$psISE.CurrentPowerShellTab.output.clear()

Monit

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość tylko do odczytu, która pobiera bieżący tekst monitu. Uwaga: funkcja Prompt może zostać zastąpiona przez profil użytkownika ™. Jeśli wynik jest inny niż prosty ciąg, ta właściwość nie zwraca nic.

# Gets the current prompt text.
$psISE.CurrentPowerShellTab.Prompt

Pokaż polecenia

Obsługiwane w programie Windows PowerShell ISE 3.0 lub nowszym i nie są obecne we wcześniejszych wersjach.

Właściwość read-write wskazująca, czy okienko Polecenia jest obecnie wyświetlane.

# 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

Obsługiwane w programie Windows PowerShell ISE 2.0 lub nowszym.

Właściwość tylko do odczytu, która pobiera tekst stanu programu PowerShellTab .

# Gets the current status text,
$psISE.CurrentPowerShellTab.StatusText

HorizontalAddOnToolsPaneOpened

Obsługiwane w programie Windows PowerShell ISE 3.0 lub nowszym i nie są obecne we wcześniejszych wersjach.

Właściwość tylko do odczytu wskazująca, czy okienko narzędzi dodatków poziomych jest obecnie otwarte.

# Gets the current state of the horizontal Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened

VerticalAddOnToolsPaneOpened

Obsługiwane w programie Windows PowerShell ISE 3.0 lub nowszym i nie są obecne we wcześniejszych wersjach.

Właściwość tylko do odczytu wskazująca, czy pionowe okienko narzędzi Dodatków jest obecnie otwarte.

# Turns on the Commands pane
$psISE.CurrentPowerShellTab.ShowCommands = $true
# Gets the current state of the vertical Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened

Zobacz też