Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add an extended Snippet for Advanced Functions #5203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
JustinGrote merged 12 commits into PowerShell:main from kilasuit:5197
Jul 23, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit Hold shift + click to select a range
1472f63
Add an extended Snippet for Advanced Functions fixes #5197
kilasuit May 24, 2025
90f312b
missed the escape chars
kilasuit May 25, 2025
fca641c
Name and prefix update
kilasuit May 28, 2025
42e594b
address comments
kilasuit May 28, 2025
a8bacf6
add new param with link to Argument Completer Docs
kilasuit May 28, 2025
3edda97
🤦🏻‍♂️ spellings, if only I could nto mkae dez mistakes 🤦🏻‍♂️
kilasuit May 28, 2025
788eab1
add multiple function aliases to show how to used them
kilasuit May 28, 2025
04eb12b
drop use of $true for param attributes
kilasuit May 28, 2025
b4ea3f9
Fix incorrect indent for prettier
JustinGrote May 31, 2025
320d729
Add more placeholders
JustinGrote May 31, 2025
ea3ffe8
Apply Prettier Formatting
JustinGrote May 31, 2025
92e5e57
Merge branch 'main' into 5197
JustinGrote Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions snippets/PowerShell.json
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,101 @@
"}"
]
},
"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",
"\t${2:Short description}",
"\t.DESCRIPTION",
"\t${3:Long description}",
"\t.EXAMPLE",
"\t${4:Example of how to use this cmdlet}",
"\t.EXAMPLE",
"\t${5:Another example of how to use this cmdlet}",
"\t.INPUTS",
"\t${6:Inputs to this cmdlet (if any)}",
"\t.OUTPUTS",
"\t${7:Output from this cmdlet (if any)}",
"\t.NOTES",
"\t${8:General notes}",
"\t.COMPONENT",
"\t${9:The component this cmdlet belongs to}",
"\t.ROLE",
"\t${10:The role this cmdlet belongs to}",
"\t.FUNCTIONALITY",
"\t${11:The functionality that best describes this cmdlet}",
"\t#>",
"\t[CmdletBinding(DefaultParameterSetName = '${12:ParameterSet1}',",
"\t\tSupportsShouldProcess,",
"\t\tPositionalBinding,",
"\t\tHelpUri = '${13:http://yourwebsiteforhelp.here}',",
"\t\tConfirmImpact = 'Medium')]",
"\t[Alias('${14:Be-lazyWithThis}','${15:lzy}','${16:Use-OldFunctionName}')]",
"\t[OutputType([${17:String}])]",
"\tparam (",
"\t\t# ${18:Param1} help description",
"\t\t[Parameter(Mandatory,",
"\t\t\tValueFromPipeline,",
"\t\t\tValueFromPipelineByPropertyName,",
"\t\t\tValueFromRemainingArguments,",
"\t\t\tPosition = 0,",
"\t\t\tParameterSetName = '${12:ParameterSet1}')]",
"\t\t[ValidateNotNull()]",
"\t\t[ValidateNotNullOrEmpty()]",
"\t\t[ValidateCount(0, 5)]",
"\t\t[ValidateSet(\"${19:sun}\", \"${20:moon}\", \"${21:earth}\")]",
"\t\t[Alias(\"${22:p1}\")]",
"\t\t$${18:Param1},",
"",
"\t\t# ${24:Param2} help description",
"\t\t[Parameter(ParameterSetName = '${12:ParameterSet1}')]",
"\t\t[AllowNull()]",
"\t\t[AllowEmptyCollection()]",
"\t\t[AllowEmptyString()]",
"\t\t[ValidateScript({ ${25:true} })]",
"\t\t[ValidateRange(0, 5)]",
"\t\t[${26:int}]",
"\t\t$${24:Param2},",
"",
"\t\t# ${28:Param3} help description",
"\t\t[Parameter(ParameterSetName = '${29:Another Parameter Set}')]",
"\t\t[ValidatePattern(\"${30:[a-z]*}\")]",
"\t\t[ValidateLength(0, 15)]",
"\t\t[${31:String}]",
"\t\t$${28:Param3},",
"",
"\t\t# ${33:Param4} help description",
"\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 = '${34:Yet Another Parameter Set}')]",
"\t\t[ArgumentCompleter({'${35:add completer script}'})]",
"\t\t[ValidateLength(0, 15)]",
"\t\t[${36:String}]",
"\t\t$${33:Param4}",
"\t)",
"",
"\tbegin {",
"\t\t${38:#BeginCodeHere}",
"\t}",
"",
"\tprocess {",
"\t\tif (\\$pscmdlet.ShouldProcess(\"${39:Target}\", \"${40:Operation}\")) {",
"\t\t\t${41:#ProcessCodeHere}",
"\t\t}",
"\t}",
"",
"\tend {",
"\t\t${42:#EndCodeHere}",
"\t}",
"",
"\tclean {",
"\t\t${43:#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",
"description": "Function definition snippet that does not contain a param block, but defines parameters inline. This syntax is commonly used in other languages. More: Get-Help about_Functions",
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /