Búsqueda de sitios web

El objeto PowerShellTab


El objeto PowerShellTab representa un entorno de ejecución de Windows PowerShell.

Métodos

Invocar (guión)

Compatible con Windows PowerShell ISE 2.0 y posteriores.

Ejecuta el script proporcionado en la pestaña PowerShell.

Nota

Este método solo funciona en otras pestañas de PowerShell, no en la pestaña de PowerShell desde la que se ejecuta. No devuelve ningún objeto o valor. Si el código modifica alguna variable, esos cambios persisten en la pestaña en la que se invocó el comando.

Script - System.Management.Automation.ScriptBlock o String El bloque de script que se ejecutará.

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

Compatible con Windows PowerShell ISE 3.0 y posteriores, y no presente en versiones anteriores.

Ejecuta el script proporcionado en la pestaña PowerShell.

Nota

Este método solo funciona en otras pestañas de PowerShell, no en la pestaña de PowerShell desde la que se ejecuta. El bloque de secuencia de comandos se ejecuta y cualquier valor que se devuelva desde la secuencia de comandos se devuelve al entorno de ejecución desde el que invocó el comando. Si el comando tarda más en ejecutarse de lo que especifica el valor millesegundosTimeout, entonces el comando falla con una excepción: "Se agotó el tiempo de espera de la operación".

Script - System.Management.Automation.ScriptBlock o String El bloque de script que se ejecutará.

[useNewScope]: valor booleano opcional cuyo valor predeterminado es $true. Si se establece en $true, se crea un nuevo ámbito dentro del cual ejecutar el comando. . No modifica el entorno de ejecución de la pestaña PowerShell especificada por el comando.

[millisegundosTimeout]: entero opcional cuyo valor predeterminado es 500. Si el comando no finaliza dentro del tiempo especificado, entonces genera una TimeoutException con el mensaje "La operación ha agotado el tiempo de espera".

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

Propiedades

Menú Complementos

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad de solo lectura que obtiene el menú Complementos para la pestaña 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

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad booleana de solo lectura que devuelve un valor $true si se puede invocar un script con el método 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

ConsolePane

Compatible con Windows PowerShell ISE 3.0 y posteriores, y no presente en versiones anteriores. En Windows PowerShell ISE 2.0, esto se llamaba CommandPane.

La propiedad de solo lectura que obtiene el objeto del editor del panel Consola.

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

DisplayName

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad de lectura y escritura que obtiene o establece el texto que se muestra en la pestaña PowerShell. De forma predeterminada, las pestañas se denominan "PowerShell #", donde # representa un número.

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

ExpandedScript

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad booleana de lectura y escritura que determina si el panel Script está expandido u oculto.

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

Archivos

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad de solo lectura que obtiene la colección de archivos de script que están abiertos en la pestaña PowerShell.

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

Producción

Esta característica está presente en Windows PowerShell ISE 2.0, pero se eliminó o se le cambió el nombre en versiones posteriores de ISE. En versiones posteriores de Windows PowerShell ISE, puede utilizar el objeto ConsolePane para los mismos fines.

La propiedad de solo lectura que obtiene el panel Salida del editor actual.

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

Inmediato

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad de solo lectura que obtiene el texto del mensaje actual. Nota: la función Preguntar puede ser anulada por el perfil del usuario. Si el resultado no es una cadena simple, esta propiedad no devuelve nada.

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

ShowCommands

Compatible con Windows PowerShell ISE 3.0 y posteriores, y no presente en versiones anteriores.

La propiedad de lectura y escritura que indica si el panel Comandos se muestra actualmente.

# 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

Compatible con Windows PowerShell ISE 2.0 y posteriores.

La propiedad de solo lectura que obtiene el texto de estado PowerShellTab.

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

Panel de herramientas AddOn horizontal abierto

Compatible con Windows PowerShell ISE 3.0 y posteriores, y no presente en versiones anteriores.

La propiedad de solo lectura que indica si el panel de herramientas Complementos horizontal está abierto actualmente.

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

Panel de herramientas AddOn vertical abierto

Compatible con Windows PowerShell ISE 3.0 y posteriores, y no presente en versiones anteriores.

La propiedad de solo lectura que indica si el panel vertical de herramientas Complementos está abierto actualmente.

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

Ver también

  • El objeto PowerShellTabCollection
  • Propósito del modelo de objetos de secuencias de comandos ISE de Windows PowerShell
  • La jerarquía del modelo de objetos ISE

Artículos relacionados