diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 61fa010c85..1595b1bc21 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -238,6 +238,100 @@ "\t}", "}" ] + }, + "Function-Advanced-Doc-Full-Example-From-ISE": { + "prefix": ["function-advanced-doc-fromISE", "cmdlet-doc-fromISE"], + "description": "Script advanced function definition with full comment-based help and parameter attributes.", + "body": [ + "function ${1:Verb-Noun} {", + "\t<#", + "\t.SYNOPSIS", + "\tShort description", + "\t.DESCRIPTION", + "\tLong description", + "\t.EXAMPLE", + "\tExample of how to use this cmdlet", + "\t.EXAMPLE", + "\tAnother example of how to use this cmdlet", + "\t.INPUTS", + "\tInputs to this cmdlet (if any)", + "\t.OUTPUTS", + "\tOutput from this cmdlet (if any)", + "\t.NOTES", + "\tGeneral notes", + "\t.COMPONENT", + "\tThe component this cmdlet belongs to", + "\t.ROLE", + "\tThe role this cmdlet belongs to", + "\t.FUNCTIONALITY", + "\tThe functionality that best describes this cmdlet", + "\t#>", + "\t[CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',", + "\t\tSupportsShouldProcess,", + "\t\tPositionalBinding", + "\t\tHelpUri = 'http://yourwebsiteforhelp.here',", + "\t\tConfirmImpact = 'Medium')]", + "\t[Alias('Be-lazyWithThis','lzy','Use-OldFunctionName')]", + "\t[OutputType([String])]", + "\tparam (", + "\t\t# Param1 help description", + "\t\t[Parameter(Mandatory,", + "\t\t\tValueFromPipeline,", + "\t\t\tValueFromPipelineByPropertyName,", + "\t\t\tValueFromRemainingArguments,", + "\t\t\tPosition = 0,", + "\t\t\tParameterSetName = 'Parameter Set 1')]", + "\t\t[ValidateNotNull()]", + "\t\t[ValidateNotNullOrEmpty()]", + "\t\t[ValidateCount(0, 5)]", + "\t\t[ValidateSet(\"sun\", \"moon\", \"earth\")]", + "\t\t[Alias(\"p1\")]", + "\t\t\\$Param1,", + "", + "\t\t# Param2 help description", + "\t\t[Parameter(ParameterSetName = 'Parameter Set 1')]", + "\t\t[AllowNull()]", + "\t\t[AllowEmptyCollection()]", + "\t\t[AllowEmptyString()]", + "\t\t[ValidateScript({ \\$true })]", + "\t\t[ValidateRange(0, 5)]", + "\t\t[int]", + "\t\t\\$Param2,", + "", + "\t\t# Param3 help description", + "\t\t[Parameter(ParameterSetName = 'Another Parameter Set')]", + "\t\t[ValidatePattern(\"[a-z]*\")]", + "\t\t[ValidateLength(0, 15)]", + "\t\t[String]", + "\t\t\\$Param3", + "", + "\t\t# Checkout the docs https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_argument_completion?view=powershell-7.5#argumentcompletions-attribute on different ways to provide Argument Completion", + "\t\t[Parameter(ParameterSetName = 'Yet Another Parameter Set')]", + "\t\t[ArgumentCompleter({'add completer script'})]", + "\t\t[ValidateLength(0, 15)]", + "\t\t[String]", + "\t\t\\$Param4", + "\t)", + "", + "\tbegin {", + "\t\t#BeginCodeHere", + "\t}", + "", + "\tprocess {", + "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", + "\t\t\t#ProcessCodeHere", + "\t\t}", + "\t}", + "", + "\tend {", + "\t\t#EndCodeHere", + "\t}", + "", + "\tclean {", + "\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", + "\t}", + "}" + ] }, "Function-Inline": { "prefix": "function-inline",