forked from jdhitsolutions/ISEScriptingGeek
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvert-CodetoSnippet.ps1
More file actions
49 lines (40 loc) · 1.74 KB
/
Convert-CodetoSnippet.ps1
File metadata and controls
49 lines (40 loc) · 1.74 KB
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
#requires -version 3.0
Function Convert-CodetoSnippet {
[cmdletbinding(SupportsShouldProcess=$True)]
Param(
[Parameter(Position=0,Mandatory=$True,
HelpMessage="Enter some code text or break, select text in the ISE and try again.")]
[ValidateNotNullorEmpty()]
[string]$Text
)
Add-Type -AssemblyName "Microsoft.VisualBasic"
$title = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a title for your snippet",$MyInvocation.mycommand.name)
if ($title) {
$description = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a description for your snippet",$MyInvocation.mycommand.name,"This is required")
if ($description) {
$author = [Microsoft.VisualBasic.Interaction]::InputBox("Enter an author for your snippet",$MyInvocation.mycommand.name,$env:username)
if (!$author) {
$author=" "
} #if author
} #if description
else {
#if no description assume user cancelled
Write-Warning -Message "No description was specified. Operation cancelled."
Return
}
if ($PSCmdlet.ShouldProcess($title) ) {
Try {
New-IseSnippet -Title $title -Text $Text -description $Description -author $Author
}
Catch {
$message = ("There was an error creating the snippet. `n`n{0} `n`nDo you want to force an overwrite?" -f $_.exception.message)
$returnValue=[microsoft.visualbasic.interaction]::Msgbox($message,"YesNo,Exclamation",$MyInvocation.MyCommand.name)
if ($returnValue -eq "yes") {
#re-run the command but this time with -Force
New-IseSnippet -Title $title -Text $Text -description $Description -author $Author -Force
}
}
} #shouldprocess
}
} #end Convert-CodeToSnippet
Set-Alias ccs Convert-CodeToSnippet