Skip to content

Commit 1472f63

Browse files
committed
Add an extended Snippet for Advanced Functions fixes #5197
1 parent d22bf3d commit 1472f63

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

snippets/PowerShell.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,93 @@
238238
"\t}",
239239
"}"
240240
]
241+
},
242+
"Function-Advanced-Doc": {
243+
"prefix": ["function-advanced-doc", "cmdlet-doc"],
244+
"description": "Script advanced function definition with full comment-based help and parameter attributes.",
245+
"body": [
246+
"function ${1:Verb-Noun} {",
247+
"\t<#",
248+
"\t.SYNOPSIS",
249+
"\tShort description",
250+
"\t.DESCRIPTION",
251+
"\tLong description",
252+
"\t.EXAMPLE",
253+
"\tExample of how to use this cmdlet",
254+
"\t.EXAMPLE",
255+
"\tAnother example of how to use this cmdlet",
256+
"\t.INPUTS",
257+
"\tInputs to this cmdlet (if any)",
258+
"\t.OUTPUTS",
259+
"\tOutput from this cmdlet (if any)",
260+
"\t.NOTES",
261+
"\tGeneral notes",
262+
"\t.COMPONENT",
263+
"\tThe component this cmdlet belongs to",
264+
"\t.ROLE",
265+
"\tThe role this cmdlet belongs to",
266+
"\t.FUNCTIONALITY",
267+
"\tThe functionality that best describes this cmdlet",
268+
"\t#>",
269+
"\t[CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',",
270+
"\t\tSupportsShouldProcess = $true,",
271+
"\t\tPositionalBinding = $false,",
272+
"\t\tHelpUri = 'http://www.microsoft.com/',",
273+
"\t\tConfirmImpact = 'Medium')]",
274+
"\t[Alias()]",
275+
"\t[OutputType([String])]",
276+
"\tparam (",
277+
"\t\t# Param1 help description",
278+
"\t\t[Parameter(Mandatory = $true,",
279+
"\t\t\tValueFromPipeline = $true,",
280+
"\t\t\tValueFromPipelineByPropertyName = $true,",
281+
"\t\t\tValueFromRemainingArguments = $false,",
282+
"\t\t\tPosition = 0,",
283+
"\t\t\tParameterSetName = 'Parameter Set 1')]",
284+
"\t\t[ValidateNotNull()]",
285+
"\t\t[ValidateNotNullOrEmpty()]",
286+
"\t\t[ValidateCount(0, 5)]",
287+
"\t\t[ValidateSet(\"sun\", \"moon\", \"earth\")]",
288+
"\t\t[Alias(\"p1\")]",
289+
"\t\t$Param1,",
290+
"",
291+
"\t\t# Param2 help description",
292+
"\t\t[Parameter(ParameterSetName = 'Parameter Set 1')]",
293+
"\t\t[AllowNull()]",
294+
"\t\t[AllowEmptyCollection()]",
295+
"\t\t[AllowEmptyString()]",
296+
"\t\t[ValidateScript({ $true })]",
297+
"\t\t[ValidateRange(0, 5)]",
298+
"\t\t[int]",
299+
"\t\t$Param2,",
300+
"",
301+
"\t\t# Param3 help description",
302+
"\t\t[Parameter(ParameterSetName = 'Another Parameter Set')]",
303+
"\t\t[ValidatePattern(\"[a-z]*\")]",
304+
"\t\t[ValidateLength(0, 15)]",
305+
"\t\t[String]",
306+
"\t\t$Param3",
307+
"\t)",
308+
"",
309+
"\tbegin {",
310+
"\t\t#BeginCodeHere",
311+
"\t}",
312+
"",
313+
"\tprocess {",
314+
"\t\tif ($pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {",
315+
"\t\t\t#ProcessCodeHere",
316+
"\t\t}",
317+
"\t}",
318+
"",
319+
"\tend {",
320+
"\t\t#EndCodeHere",
321+
"\t}",
322+
"",
323+
"\tclean {",
324+
"\t\t#CleanCodeHere - Added in 7.3 for more information see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods?view=powershell-7.5#clean",
325+
"\t}",
326+
"}"
327+
]
241328
},
242329
"Function-Inline": {
243330
"prefix": "function-inline",

0 commit comments

Comments
 (0)