forked from jdhitsolutions/ISEScriptingGeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISEScriptingGeek.psm1
179 lines (146 loc) · 17.7 KB
/
ISEScriptingGeek.psm1
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#requires -version 4.0
<#
A collection of add-ons for the Powershell 4.0 ISE
last updated 22 September 2015
#>
#dot source the scripts
. $psScriptRoot\New-CommentHelp.ps1
. $psScriptRoot\ConvertTo-TextFile.ps1
. $psScriptRoot\Convert-AliasDefinition.ps1
. $psScriptRoot\Convertall.ps1
. $psScriptRoot\ConvertFrom-Alias.ps1
. $psScriptRoot\Sign-ISEScript.ps1
. $psScriptRoot\Print-ISEFile.ps1
. $psScriptRoot\Convert-CodeToSnippet.ps1
. $psScriptRoot\Out-ISETab.ps1
. $psScriptRoot\Open-SelectedinISE.ps1
. $psScriptRoot\Convert-CommandToHash.ps1
. $psScriptRoot\Get-CommandMetadata.ps1
. $psScriptRoot\CycleISETabs.ps1
. $psScriptRoot\New-DSCResourceSnippet.ps1
. $psScriptRoot\New-PSCommand.ps1
. $psScriptRoot\New-PSDriveHere.ps1
. $psScriptRoot\Find-InFile.ps1
. $psScriptRoot\CIMScriptMaker.ps1
. $psScriptRoot\Convert-ISEComment.ps1
. $psScriptRoot\ConvertTo-CommentHelp.ps1
. $psScriptRoot\Get-ScriptComments.ps1
. $psScriptRoot\Get-ASTScriptProfile.ps1
. $psScriptRoot\Get-SearchResult.ps1
. $psScriptRoot\New-Inputbox.ps1
. $psScriptRoot\Bookmarks.ps1
. $psScriptRoot\Reload-ISEFile.ps1
. $psScriptRoot\Edit-Snippet.ps1
. $psScriptRoot\Copy-ToWord.ps1
. $psScriptRoot\CloseAllFiles.ps1
. $psScriptRoot\CurrentProjects.ps1
<#
Add an ISE Menu shortcut to save all open files.
This will only save files that have previously been saved
with a title. Anything that is untitled still needs
to be manually saved first.
#>
$saveall={
$psise.CurrentPowerShellTab.files |
where {-Not ($_.IsUntitled)} |
foreach {
$_.Save()
}
}
#a function to display scripting about topics
Function Get-ScriptingHelp {
Param()
Get-Help about_Scripting* | Select Name,Synopsis |
Out-GridView -Title "Select one or more help topics" -OutputMode Multiple |
foreach { $_ | get-help -ShowWindow}
}
#a function to for parameters for the current script
#using Show-Command
Function Start-MyScript {
Param([string]$Path = $psise.currentfile.FullPath)
If (Test-path $Path) {
Show-Command -Name $path
}
else {
Write-Warning "No file found"
}
} #end function
#create a custom sub menu
$jdhit = $psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ISE Scripting Geek",$null,$null)
#create some child menus for better organization
$Book = $jdhit.Submenus.add("Bookmarks",$Null,$Null)
$convert = $jdhit.Submenus.Add("Convert",$Null,$null)
$dates = $jdhit.submenus.Add("Dates and Times",$Null,$Null)
$files = $jdhit.Submenus.Add("Files",$Null,$null)
$work = $jdhit.submenus.Add("Work",$Null,$null)
#add my menu addons in sort of alphabetical order
$jdhit.submenus.Add("Add Help",{New-CommentHelp},"ALT+H") | Out-Null
$convert.submenus.Add("Convert All Aliases",{ConvertTo-Definition $psise.CurrentFile.Editor.SelectedText},$Null) | Out-Null
$convert.submenus.Add("Convert Help to Comment Help",{ConvertTo-CommentHelp},"Ctrl+Shift+H") | Out-Null
$convert.submenus.Add("Convert Code to Snippet",{Convert-CodetoSnippet -Text $psise.CurrentFile.Editor.SelectedText},"CTRL+ALT+S")
$convert.submenus.Add("Convert Selected to Region",{
$psise.CurrentFile.Editor.InsertText("#region`r`r$($psise.CurrentFile.Editor.SelectedText)`r`r#endregion")},$null)
$convert.submenus.Add("Convert Selected From Alias",{ConvertFrom-Alias},$Null) | Out-Null
$convert.submenus.Add("Convert Single Selected to Alias",{Convert-AliasDefinition $psise.CurrentFile.Editor.SelectedText -ToAlias},$Null) | Out-Null
$convert.submenus.Add("Convert Single Selected to Command",{Convert-AliasDefinition $psise.CurrentFile.Editor.SelectedText -ToDefinition},$Null) | Out-Null
$convert.Submenus.Add("Convert to lowercase",
{$psise.currentfile.editor.insertText($psise.CurrentFile.Editor.SelectedText.toLower())},"CTRL+ALT+L") | Out-Null
$convert.Submenus.Add("Convert to parameter hash",{Convert-CommandToHash},"Ctrl+ALT+H") | Out-Null
$convert.submenus.Add("Convert to text file",{ConvertTo-TextFile}, "ALT+T") | Out-Null
$convert.Submenus.Add("Convert to uppercase",{$psise.currentfile.editor.insertText($psise.CurrentFile.Editor.SelectedText.toUpper())},"CTRL+ALT+U") | Out-Null
$jdhit.Submenus.add("Create new DSC Resource Snippets",{Get-DSCResource | New-DSCResourceSnippet},$Null) | Out-Null
$jdhit.submenus.add("Edit your ISE profile",{
If (Test-Path $Profile) {
psedit $profile
}
else {
write-warning "Cannot find $profile"
}
},$Null) | Out-Null
$convert.Submenus.Add("Convert to block comment",{ConvertTo-MultiLineComment},"Ctrl+Alt+B") | Out-Null
$convert.Submenus.Add("Convert from block comment",{ConvertFrom-MultiLineComment},"Ctrl+Alt+C") | Out-Null
$files.Submenus.Add("Close All Files",{CloseAllFiles},"Ctrl+Alt+F4") | Out-Null
$files.Submenus.Add("Close All Files Except Active",{CloseAllFilesButCurrent},"Ctrl+Shift+F4") | Out-Null
$files.submenus.Add("Edit snippets",{Edit-Snippet},$Null) | Out-Null
$files.submenus.Add("Get Script Profile",{Get-ASTProfile},$Null) | Out-Null
$jdhit.submenus.Add("Get Scripting Help",{Get-ScriptingHelp},$Null) | Out-Null
$files.Submenus.add("Find in File",{Find-InFile},"Ctrl+Shift+F") | Out-Null
$dates.submenus.Add("Insert Datetime",{$psise.CurrentFile.Editor.InsertText(("{0} {1}" -f (get-date),(get-wmiobject win32_timezone -property StandardName).standardName))},"ALT+F5") | out-Null
$dates.submenus.Add("Insert Short Date",{$psISE.currentfile.editor.inserttext((Get-Date).ToShortDateString())},"ALT+F6") | out-Null
$dates.submenus.Add("Insert Short Time",{$psISE.currentfile.editor.inserttext((Get-Date).ToShortTimeString())},"ALT+F7") | out-Null
$dates.submenus.Add("Insert Short Date Time",{$psISE.currentfile.editor.inserttext((Get-Date -Format g))},"ALT+F8") | out-Null
$dates.submenus.Add("Insert Long Date",{$psISE.currentfile.editor.inserttext((Get-Date -displayhint Date))},"ALT+F9") | out-Null
$dates.submenus.Add("Insert UTC Date",{$psISE.currentfile.editor.inserttext((Get-Date -format u))},"ALT+F10") | out-Null
$dates.submenus.Add("Insert GMT Date",{$psISE.currentfile.editor.inserttext((Get-Date -format r))},"ALT+F11") | out-Null
$jdhit.Submenus.add("New CIM Command",{New-CimCommand},$Null) | Out-Null
$files.submenus.Add("Open Current Script Folder",{Invoke-Item (split-path $psise.CurrentFile.fullpath)},"ALT+O") | Out-Null
$files.Submenus.Add("Open Selected File",{Open-SelectedISE},"Ctrl+Alt+F") | Out-Null
$files.Submenus.Add("Reload Selected File",{Reset-ISEFile},"Ctrl+Alt+R") | Out-Null
$jdhit.submenus.Add("Print Script",{Send-ToPrinter},"CTRL+ALT+P") | Out-Null
$jdhit.submenus.Add("Run Script",{Start-MyScript},"CTRL+SHIFT+Z") | Out-Null
$files.Submenus.Add("Save All Files",$saveall,"Ctrl+Shift+A") | Out-Null
$files.submenus.Add("Save File as ASCII",{$psISE.CurrentFile.Save([Text.Encoding]::ASCII)}, $null) | Out-Null
$jdhit.Submenus.Add("Search selected text with Bing",{Get-SearchResult -SearchEngine Bing},"Shift+Alt+B") | Out-Null
$jdhit.Submenus.Add("Search selected text with Google",{Get-SearchResult -SearchEngine Google},"Shift+Alt+G") | Out-Null
$jdhit.Submenus.Add("Send to Word",{Copy-ToWord},"Ctrl+Alt+W") | Out-Null
$jdhit.Submenus.Add("Send to Word Colorized",{Copy-ToWord -Colorized},$Null) # | Out-Null
$jdhit.submenus.Add("Sign Script",{Write-Signature},$null) | Out-Null
$jdhit.Submenus.Add("Switch next tab",{Get-NextISETab},"Ctrl+ALT+T") | Out-Null
$jdhit.Submenus.Add("Use local help",{$psise.Options.UseLocalHelp = $True},$Null) | Out-Null
$jdhit.Submenus.Add("Use online help",{$psise.Options.UseLocalHelp = $False},$Null) | Out-Null
$book.Submenus.Add("Add ISE Bookmark",{Add-ISEBookmark},"Ctrl+Shift+N") | Out-Null
$book.Submenus.Add("Clear ISE Bookmarks",{del $MyBookmarks},"Ctrl+Shift+C") | Out-Null
$book.Submenus.Add("Get ISE Bookmark",{Get-ISEBookmark},"Ctrl+Shift+G") | Out-Null
$book.Submenus.Add("Open ISE Bookmark",{Open-ISEBookmark},"Ctrl+Shift+O") | Out-Null
$book.Submenus.Add("Remove ISE Bookmark",{Remove-ISEBookmark},"Ctrl+Shift+K") | Out-Null
$book.Submenus.Add("Update ISE Bookmark",{Update-ISEBookmark},"Ctrl+Shift+X") | Out-Null
$work.submenus.Add("Add current file to work",{Add-CurrentProject -List $currentProjectList},"CTRL+Alt+A") | Out-Null
$work.submenus.Add("Edit current work file",{Edit-CurrentProject -List $currentProjectList},"CTRL+Alt+E") | Out-Null
$work.submenus.Add("Open current work files",{Import-CurrentProject -List $currentProjectList},"CTRL+Alt+I") | Out-Null
#define some ISE specific variables
$MySnippets = "$Env:USERPROFILE\Documents\WindowsPowerShell\Snippets"
$MyModules = Join-Path -Path $home -ChildPath "documents\WindowsPowerShell\Modules"
$MyPowerShell = "$env:userprofile\Documents\WindowsPowerShell"
$MyBookmarks = Join-Path -path $myPowerShell -ChildPath "myISEBookmarks.csv"
$CurrentProjectList = Join-Path -Path $env:USERPROFILE\Documents\WindowsPowerShell -ChildPath "currentWork.txt"
Export-ModuleMember -Function * -Alias * -Variable MySnippets,MyModules,MyPowerShell,MyBookmarks,CurrentProjectList