Objet PowerShellTab
L’objet PowerShellTab représente un environnement d’exécution Windows PowerShell.
Méthode
Invoke( Script )
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Exécute le script donné sous l’onglet PowerShell.
Note
Cette méthode fonctionne uniquement sur d’autres onglets PowerShell, et non sur l’onglet PowerShell à partir duquel il est exécuté. Elle ne retourne aucun objet ou valeur. Si le code modifie une variable, ces modifications persistent sur l’onglet sur lequel la commande a été appelée.
script - System.Management.Automation.ScriptBlock ou String Le bloc de script à exécuter.
# 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 )
Pris en charge dans Windows PowerShell ISE 3.0 et versions ultérieures, et non présents dans les versions antérieures.
Exécute le script donné sous l’onglet PowerShell.
Note
Cette méthode fonctionne uniquement sur d’autres onglets PowerShell, et non sur l’onglet PowerShell à partir duquel il est exécuté. Le bloc de script est exécuté et toute valeur retournée par le script est retournée à l’environnement d’exécution à partir duquel vous avez appelé la commande. Si la commande prend plus de temps à s’exécuter que la valeur millesecondsTimeout spécifiée, la commande échoue avec une exception : « L’opération a expiré ».
script - System.Management.Automation.ScriptBlock ou String Le bloc de script à exécuter.
[useNewScope] : valeur booléenne facultative par défaut $true
Si définie sur $true
, une nouvelle étendue est créée dans laquelle exécuter la commande. Il ne modifie pas l’environnement d’exécution de l’onglet PowerShell spécifié par la commande.
[millisecondsTimeout] - Entier facultatif par défaut 500. Si la commande ne se termine pas dans le délai spécifié, la commande génère une TimeoutException avec le message « L’opération a expiré ».
# 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)}
Propriétés
AddOnsMenu
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété en lecture seule qui obtient le menu Compléments pour l’onglet 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
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété booléenne en lecture seule qui retourne une valeur $true
si un script peut être appelé avec la méthode 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
Pris en charge dans Windows PowerShell ISE 3.0 et versions ultérieures, et non présents dans les versions antérieures. Dans Windows PowerShell ISE 2.0, il a été nommé CommandPane.
Propriété en lecture seule qui obtient le volet Console 'éditeur objet.
# Gets the Console Pane editor.
$psISE.CurrentPowerShellTab.ConsolePane
DisplayName
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété en lecture-écriture qui obtient ou définit le texte affiché sous l’onglet PowerShell. Par défaut, les onglets sont nommés « PowerShell # », où le # représente un nombre.
$newTab = $psISE.PowerShellTabs.Add()
# Change the DisplayName of the new PowerShell tab.
$newTab.DisplayName = 'Brand New Tab'
ExpandedScript
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété booléenne en lecture-écriture qui détermine si le volet Script est développé ou masqué.
# Toggle the expanded script property to see its effect.
$psISE.CurrentPowerShellTab.ExpandedScript = !$psISE.CurrentPowerShellTab.ExpandedScript
Fichiers
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété en lecture seule qui obtient la collection de fichiers de script qui sont ouverts dans l’onglet PowerShell.
$newFile = $psISE.CurrentPowerShellTab.Files.Add()
$newFile.Editor.Text = "a`r`nb"
# Gets the line count
$newFile.Editor.LineCount
Sortie
Cette fonctionnalité est présente dans Windows PowerShell ISE 2.0, mais a été supprimée ou renommée dans les versions ultérieures de l’ISE. Dans les versions ultérieures de Windows PowerShell ISE, vous pouvez utiliser l’objet ConsolePane à des fins identiques.
Propriété en lecture seule qui obtient le volet Sortie de l’éditeur de actuel.
# Clears the text in the Output pane.
$psISE.CurrentPowerShellTab.output.clear()
Prompt
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété en lecture seule qui obtient le texte d’invite actuel. Remarque : la fonction Invite peut être remplacée par le profil de l’utilisateur ™. Si le résultat est autre qu’une chaîne simple, cette propriété ne retourne rien.
# Gets the current prompt text.
$psISE.CurrentPowerShellTab.Prompt
ShowCommands
Pris en charge dans Windows PowerShell ISE 3.0 et versions ultérieures, et non présents dans les versions antérieures.
Propriété en lecture-écriture qui indique si le volet Commandes est actuellement affiché.
# 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
Pris en charge dans Windows PowerShell ISE 2.0 et versions ultérieures.
Propriété en lecture seule qui obtient le texte d’état PowerShellTab.
# Gets the current status text,
$psISE.CurrentPowerShellTab.StatusText
HorizontalAddOnToolsPaneOpened
Pris en charge dans Windows PowerShell ISE 3.0 et versions ultérieures, et non présents dans les versions antérieures.
Propriété en lecture seule qui indique si le volet d’outils de Add-Ons horizontal est actuellement ouvert.
# Gets the current state of the horizontal Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened
VerticalAddOnToolsPaneOpened
Pris en charge dans Windows PowerShell ISE 3.0 et versions ultérieures, et non présents dans les versions antérieures.
Propriété en lecture seule qui indique si le volet d’outils de Add-Ons vertical est actuellement ouvert.
# Turns on the Commands pane
$psISE.CurrentPowerShellTab.ShowCommands = $true
# Gets the current state of the vertical Add-ons tool pane.
$psISE.CurrentPowerShellTab.HorizontalAddOnToolsPaneOpened