Compartilhar via


O Objeto PowerShellTab

O objeto PowerShellTab representa um ambiente de runtime do PowerShell do Windows.

Methods

Invoke( Script )

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

Executa o script fornecido na aba PowerShell.

Observação

Esse método só funciona em outras abas do PowerShell, não na aba PowerShell de onde ele é executado. Não retorna nenhum objeto ou valor. Se o código modificar qualquer variável, essas mudanças persistem na aba contra a qual o comando foi invocado.

  • Script - System.Management.Automation.ScriptBlock ou String - O bloco de script a ser executado.
# 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 fornecido na aba PowerShell.

Observação

Esse método só funciona em outras abas do PowerShell, não na aba PowerShell de onde ele é executado. O bloco de script é executado e qualquer valor retornado pelo script é devolvido ao ambiente de execução de onde você invocou o comando. Se o comando demorar mais para ser executado do que o valor de tempo de expiração dos milésegundos 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 ser executado.
  • [useNewScope] - Booleano opcional que padrão é $true - Se definido para $true, então um novo escopo é criado dentro do qual executar o comando. Ele não modifica o ambiente de execução da aba PowerShell especificado pelo comando.
  • [milisegundosTempo] - Inteiro opcional que padrão é 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."
# 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 versões posteriores.

A propriedade de somente leitura que abre o menu de complementos para a aba 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 versões posteriores.

A propriedade booleana somente leitura que retorna 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, isso era chamado de CommandPane.

A propriedade somente leitura que recebe o objeto do editor do painel do console.

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

DisplayName

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade de leitura-gravação que recebe ou define o texto que é exibido na aba PowerShell. Por padrão, as tabulações são chamadas de "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 versões 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

Arquivos

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade somente leitura que recebe a coleção de arquivos de script abertos na aba PowerShell.

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

Saída

Esse recurso está presente no Windows PowerShell ISE 2.0, mas foi removido ou renomeado em versões posteriores do ISE. Em versões posteriores do Windows PowerShell ISE, você pode usar o objeto ConsolePane para os mesmos propósitos.

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

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

Rápido

Suportado no Windows PowerShell ISE 2.0 e versões posteriores.

A propriedade somente leitura que recebe o texto atual do prompt. Nota: a prompt função pode ser sobrescrevida pelo perfil do usuário. Se o resultado for diferente de uma cadeia simples, então essa 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-gravação que indica se o painel de Comandos está exibido atualmente.

# 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 versões posteriores.

A propriedade somente leitura que recebe o texto de status 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 somente 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 somente leitura indica se o painel vertical Add-Ons ferramenta está aberto no momento.

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

Consulte Também