-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISE_Add-on.ps1
38 lines (35 loc) · 1.78 KB
/
ISE_Add-on.ps1
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
<#
# from https://learn-powershell.net/2016/02/01/quickly-create-a-powershell-snippet-in-the-ise-using-an-add-on/
#>
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("Save selection as Snippet",{
$Text = $psISE.CurrentFile.Editor.SelectedText
If (($Text -notmatch '^\s+$' -AND $Text.length -gt 0)) {
Try {
[void][Microsoft.VisualBasic.Interaction]
} Catch {
Add-Type –assemblyName Microsoft.VisualBasic
}
$Name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Snippet Name", "Snippet Name")
$Description = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Snippet Description", "Snippet Description")
If ($Name -and $Description) {
New-IseSnippet -Description $Description -Title $Name -Text $Text –Force
Write-Host "New Snippet created!" -ForegroundColor Yellow -BackgroundColor Black
}
}
},"Alt+F8")
[void]$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add("Save whole script as Snippet",{
$Text = $psISE.CurrentFile.Editor.Text
If (($Text -notmatch '^\s+$' -AND $Text.length -gt 0)) {
Try {
[void][Microsoft.VisualBasic.Interaction]
} Catch {
Add-Type –assemblyName Microsoft.VisualBasic
}
$Name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Snippet Name", "Snippet Name")
$Description = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Snippet Description", "Snippet Description")
If ($Name -and $Description -AND ($Text -notmatch '^\s+$' -AND $Text.length -gt 0)) {
New-IseSnippet -Description $Description -Title $Name -Text $Text –Force
Write-Host "New Snippet created!" -ForegroundColor Yellow -BackgroundColor Black
}
}
},"Alt+F5")