Partilhar via


O Objeto PowerShellTab

O objeto PowerShellTab representa um ambiente de execução PowerShell do Windows.

Methods

Invoke( Script )

Suportado no Windows PowerShell ISE 2.0 e posteriores.

Executa o script indicado no separador PowerShell.

Observação

Este método só funciona noutros separadores PowerShell, não no separador PowerShell de onde é executado. Não devolve nenhum objeto ou valor. Se o código modificar alguma variável, essas alterações persistem no separador contra o qual o comando foi invocado.

  • Script - System.Management.Automation.ScriptBlock ou String - O bloco de script a executar.
# 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 )

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

Executa o script indicado no separador PowerShell.

Observação

Este método só funciona noutros separadores PowerShell, não no separador PowerShell de onde é executado. O bloco de script é executado e qualquer valor devolvido pelo script é devolvido ao ambiente de execução de onde invocaste o comando. Se o comando demorar mais a executar do que o valor de tempo de expiração especificado, então o comando falha com uma exceção: "A operação expirou."

  • Script - System.Management.Automation.ScriptBlock ou String - O bloco de script a executar.
  • [useNewScope] - Booleano opcional que por defeito é $true - Se definido para $true, então é criado um novo escopo dentro do qual executar o comando. Não modifica o ambiente de execução do separador PowerShell especificado pelo comando.
  • [milissegundosTempo] - Número inteiro opcional que por defeito é 500. - Se o comando não terminar dentro do tempo especificado, então o comando gera uma TimeoutException com a mensagem "A operação expirou o tempo."
# 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)}

Propriedades

AddOnsMenu

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade de apenas leitura que recebe o menu de complementos para o separador 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

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade Booleana de apenas leitura que devolve um $true valor se um script pode ser invocado com o 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'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

ConsolePane

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores. No Windows PowerShell ISE 2.0, isto era chamado CommandPane.

A propriedade de apenas leitura que recebe o objeto editor do painel da consola.

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

Nome de Exibição

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade de leitura-escrita que recebe ou define o texto que é mostrado no separador PowerShell. Por defeito, as tabulações chamam-se "PowerShell #", onde o # representa um número.

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

ExpandedScript

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade booleana de leitura-escrita que determina se o painel do Script está expandido ou oculto.

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

Ficheiros

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade de apenas leitura que obtém a coleção de ficheiros de script abertos no separador PowerShell.

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

Resultado

Esta funcionalidade está presente no Windows PowerShell ISE 2.0, mas foi removida ou renomeada em versões posteriores do ISE. Nas versões posteriores do Windows PowerShell ISE, pode usar o objeto ConsolePane para os mesmos fins.

A propriedade de apenas leitura que recebe o painel de Saída do editor atual.

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

Pronta

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade de apenas leitura que recebe o texto de prompt atual. Nota: a prompt função pode ser sobreposta pelo perfil do utilizador. Se o resultado for diferente de uma cadeia simples, então esta propriedade não retorna nada.

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

ShowCommands

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

A propriedade de leitura-escrita que indica se o painel de Comandos está atualmente exibido.

# 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

Suportado no Windows PowerShell ISE 2.0 e posteriores.

A propriedade de apenas leitura que recebe o texto de estado do PowerShellTab .

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

HorizontalAddOnToolsPaneAberto

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

A propriedade de apenas leitura indica se o painel horizontal Add-Ons ferramenta está atualmente aberto.

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

VerticalAddOnToolsPaneAberto

Suportado no Windows PowerShell ISE 3.0 e posteriores, e não presente em versões anteriores.

A propriedade de somente leitura indica se o painel vertical Add-Ons ferramenta está atualmente aberto.

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

Ver também