Partilhar via


Objeto PowerShellTab

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

Métodos

Invoke( Script )

Suportado no Windows PowerShell ISE 2.0 e posterior.

Executa o script fornecido na guia PowerShell.

Nota

Esse método só funciona em outras guias do PowerShell, não na guia PowerShell a partir da qual ele é executado. Ele não retorna nenhum objeto ou valor. Se o código modificar qualquer variável, essas alterações persistirão na guia 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], milissegundosTimeout )

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

Executa o script fornecido na guia PowerShell.

Nota

Esse método só funciona em outras guias do PowerShell, não na guia PowerShell a partir da qual ele é executado. O bloco de script é executado e qualquer valor retornado do script é retornado para o ambiente de execução do qual você invocou o comando. Se o comando demorar mais para ser executado do que o valor millesecondsTimeout especifica, o comando falhará com uma exceção: "A operação atingiu o tempo limite".

Script - System.Management.Automation.ScriptBlock ou String O bloco de script a ser executado.

[useNewScope] - Booleano opcional que assume $true como padrão Se definido como $true, então um novo escopo é criado dentro do qual executar o comando. Ele não modifica o ambiente de tempo de execução da guia PowerShell especificado pelo comando.

[milissegundosTempo limite] - Inteiro opcional que tem como padrão 500. Se o comando não terminar dentro do tempo especificado, o comando gerará 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 posterior.

A propriedade somente leitura que obtém o menu Complementos para a guia 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 posterior.

A propriedade Boolean 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 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

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores. No Windows PowerShell ISE 2.0, isso foi chamado de CommandPane.

A propriedade somente leitura que obtém o objeto Editor do painel Console.

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

DisplayName

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade leitura-gravação que obtém ou define o texto exibido na guia PowerShell. Por padrão, as guias 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 posterior.

A propriedade Boolean de leitura-gravação que determina se o painel Script é 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 posterior.

A propriedade somente leitura que obtém a coleção de arquivos de script abertos na guia 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 fins.

A propriedade somente leitura que obtém o painel Saída do editor atual.

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

Prompt

Suportado no Windows PowerShell ISE 2.0 e posterior.

A propriedade somente leitura que obtém o texto do prompt atual. Nota: a função Prompt pode ser substituída pelo perfil do ™usuário. Se o resultado for diferente de uma cadeia de caracteres simples, essa propriedade não retornará nada.

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

ShowCommands

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

A propriedade read-write que indica se o painel Comandos é exibido no momento.

# 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 posterior.

A propriedade somente leitura que obtém o texto de status PowerShellTab.

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

HorizontalAddOnToolsPaneOpened

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

A propriedade somente leitura que indica se o painel de ferramentas Complementos horizontal está aberto no momento.

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

VerticalAddOnToolsPaneOpened

Com suporte no Windows PowerShell ISE 3.0 e posterior, e não presente em versões anteriores.

A propriedade somente leitura que indica se o painel de ferramentas Complementos verticais 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