Compartilhar via


O objeto PowerShellTab

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

Métodos

Invoke( Script )

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

Executa o script fornecido na guia PowerShell.

Nota

Esse método só funciona em outras guias do PowerShell, não na guia do PowerShell 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 na 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 ISE 3.0 do Windows PowerShell 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 do PowerShell 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 levar mais tempo para ser executado do que o millesecondsTimeout valor especificar, 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] – booliano opcional que usa como padrão $true Se definido como $true, um novo escopo é criado no qual executar o comando. Ele não modifica o ambiente de runtime da guia powershell especificada pelo comando.

[milissegundosTimeout] – inteiro opcional que usa como padrão 500. Se o comando não for concluído dentro do tempo especificado, o comando gerará um TimeoutException com a mensagem "A operação atingiu o tempo limite".

# 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

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade somente leitura que obtém o menu Complementos da 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

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade Boolean somente leitura que retorna um valor $true se um script puder 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 ISE 3.0 do Windows PowerShell e posterior e não presente em versões anteriores. No ISE 2.0 do Windows PowerShell, isso foi nomeado CommandPane.

A propriedade somente leitura que obtém o painel console editor objeto.

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

DisplayName

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade de leitura/gravação que obtém ou define o texto exibido na guia do PowerShell. Por padrão, as guias são chamadas de "PowerShell #", em que o # representa um número.

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

ExpandedScript

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade booliana de leitura/gravação que determina se o painel Script está expandido ou oculto.

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

Limas

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade somente leitura que obtém a coleção de arquivos de script que estão 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 ISE 2.0 do Windows PowerShell, mas foi removido ou renomeado em versões posteriores do ISE. Em versões posteriores do ISE do Windows PowerShell, você pode usar o objeto ConsolePane para as mesmas finalidades.

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

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

Rápido

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

A propriedade somente leitura que obtém o texto do prompt atual. Observação: 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 ISE 3.0 do Windows PowerShell e posterior e não presente em versões anteriores.

A propriedade read-write que indica se o painel 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

Com suporte no ISE 2.0 do Windows PowerShell e posterior.

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

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

HorizontalAddOnToolsPaneOpened

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

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

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

VerticalAddOnToolsPaneOpened

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

A propriedade somente leitura que indica se o painel de ferramentas de Add-Ons vertical 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