salut,


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Function Add-AddOns
{
<# 
.synopsis
 affiche et/ou créer des add-ons
.parameter List
  affiche tous les noms des add-ons disponibles
.parameter Name
  nom du add-on
.parameter ShortCut
  un raccourcis pour le add-on
.parameter Action
  un bloc de script qui va s'executer à l'appel du add-on
.example
  Add-AddOns -List
.example
 PS> Add-AddOns -n "Effacer le volet de Script" -s "ctrl+shift+b" -a {   
 >>   $psISE.CurrentFile.Editor.Clear()
 >>  }

  Créer un add-on pour effacer le volet script
.example
  PS> Add-AddOns -RemoveAll
  
  Supprime tous les add-Ons 
.example
  PS> Add-AddOns -RemoveItem 1
  
  Supprime l'add-on ayant l'index 1
.example
  PS> $sb = { Invoke-Expression 'c:\script.ps1'  }
  PS> Add-AddOns "script.ps1" "Ctrl+shift+q" $sb
  
  Execute le script 'c:\script.ps1'
#> 
  [CmdletBinding(DefaultParameterSetName='List')]
  Param(
   [Parameter(Mandatory=$False,Position=0,ParameterSetName='List')]
   [Switch]$List,
   [Parameter(Mandatory=$True,Position=0,ParameterSetName='RemoveAll')]
   [Switch]$RemoveAll,
   [Parameter(Mandatory=$True,Position=0,ParameterSetName='RemoveItem')]
   [int]$RemoveItem,
   [Parameter(Mandatory=$True,Position=0,ParameterSetName='Name')]
   [String]$Name,
   [Parameter(Mandatory=$false,Position=1,ParameterSetName='Name')]
   $ShortCut=$null,
   [Parameter(Mandatory=$True,Position=2,ParameterSetName='Name')]
   [ScriptBlock]$Action
  )
  if($Host.Name -ne 'Windows PowerShell ISE Host') 
  { throw "fonctionne uniquement dans l'environment ISE" }
  Switch ($PSCmdlet.ParameterSetName)
  {
     "List"
     {
        $Items = $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus
        for($i=0;$i -le $items.count-1;$i++) 
         { Select -inp $Items @{n="Index";e={$i}},
            @{n="Name";e={$_.Item($i).DisplayName}}   
         }
     }
     "RemoveAll"
     { 
       $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear() 
     }
     "RemoveItem"
     { 
       $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.RemoveAt($RemoveItem)
     }
     "Name"
     {
       $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add($Name,$Action,$ShortCut)
     }
  }
}
vous pouvez par la suite, mettre cette fonction dans votre profile_ise