From ba742d64414013d60dfecdd92c5e0deb915110b4 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 29 Jan 2022 10:18:00 -0800 Subject: [PATCH 01/14] Add Function-Help Snippet --- snippets/PowerShell.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 5c1b58e2cc..8355575c9f 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -561,6 +561,25 @@ ], "description": "Comment-based help for an advanced function snippet" }, + "Function-Help": { + "prefix": "help-function", + "body": [ + "<#", + ".SYNOPSIS", + "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", + ".DESCRIPTION", + "\t${2:A longer description of the function, its purpose, common use cases, etc.}", + ".NOTES", + "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", + ".LINK", + "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", + ".EXAMPLE", + "\t${5:Test-MyTestFunction -Verbose}", + "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", + "#>" + ], + "description": "Comment-based help for an advanced function snippet" + }, "Parameter": { "prefix": "parameter", "body": [ From 096c543e043fc96089a0b8df0f4862a7ef2b206d Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 09:32:24 -0800 Subject: [PATCH 02/14] Sort file properly --- snippets/PowerShell.json | 1295 +++++++++++++++++++------------------- 1 file changed, 648 insertions(+), 647 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 8355575c9f..04d6290213 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,69 +1,280 @@ // The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { - "ModuleManifest": { - "prefix": "manifest", + "ArgumentCompleterAttribute ScriptBlock": { + "prefix": "completer-scriptblock", + "description": "ArgumentCompleter parameter attribute script block definition", "body": [ - "@{", - "\t# If authoring a script module, the RootModule is the name of your .psm1 file", - "\tRootModule = '${module:MyModule}.psm1'", - "", - "\tAuthor = '${author:Cool Person }'", - "", - "\tCompanyName = '${company:Contoso Inc.}'", - "", - "\tModuleVersion = '${ModuleVersion:0.1}'", - "", - "\t# Use the New-Guid command to generate a GUID, and copy/paste into the next line", - "\tGUID = ''", - "", - "\tCopyright = '2017 ${company:Copyright Holder}'", - "", - "\tDescription = '${Description:What does this module do?}'", - "", - "\t# Minimum PowerShell version supported by this module (optional, recommended)", - "\t# PowerShellVersion = ''", - "", - "\t# Which PowerShell Editions does this module work with? (Core, Desktop)", - "\tCompatiblePSEditions = @('Desktop', 'Core')", - "", - "\t# Which PowerShell functions are exported from your module? (eg. Get-CoolObject)", - "\tFunctionsToExport = @('')", - "", - "\t# Which PowerShell aliases are exported from your module? (eg. gco)", - "\tAliasesToExport = @('')", - "", - "\t# Which PowerShell variables are exported from your module? (eg. Fruits, Vegetables)", - "\tVariablesToExport = @('')", - "", - "\t# PowerShell Gallery: Define your module's metadata", - "\tPrivateData = @{", - "\t\tPSData = @{", - "\t\t\t# What keywords represent your PowerShell module? (eg. cloud, tools, framework, vendor)", - "\t\t\tTags = @('${tag1:cooltag1}', '${tag2:cooltag2}')", - "", - "\t\t\t# What software license is your code being released under? (see https://opensource.org/licenses)", - "\t\t\tLicenseUri = ''", - "", - "\t\t\t# What is the URL to your project's website?", - "\t\t\tProjectUri = ''", - "", - "\t\t\t# What is the URI to a custom icon file for your project? (optional)", - "\t\t\tIconUri = ''", - "", - "\t\t\t# What new features, bug fixes, or deprecated features, are part of this release?", - "\t\t\tReleaseNotes = @'", - "'@", - "\t\t}", - "\t}", - "", - "\t# If your module supports updateable help, what is the URI to the help archive? (optional)", - "\t# HelpInfoURI = ''", - "}" - ], - "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata." + "{", + "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", + "\tparam(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "ArgumentCompleterAttribute with ScriptBlock": { + "prefix": "completer-attribute", + "description": "ArgumentCompleter parameter attribute with script block definition", + "body": [ + "[ArgumentCompleter({", + "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", + "\tparam(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "})]" + ] + }, + "CalculatedProperty": { + "prefix": "Calculated-Property", + "description": "Creates a Calculated Property typically used with Select-Object.", + "body": [ + "@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" + ] + }, + "Class": { + "prefix": "class", + "description": "Class definition snippet", + "body": [ + "class ${1:ClassName} {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "comment block": { + "prefix": "comment", + "description": "Comment block snippet", + "body": [ + "<#", + " # ${0:$TM_SELECTED_TEXT}", + " #>" + ] + }, + "Comment-Help": { + "prefix": "comment-help", + "description": "Comment-based help for an advanced function snippet", + "body": [ + "<#", + ".SYNOPSIS", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tPS C:\\> ", + "\tExplanation of what the example does", + ".INPUTS", + "\tInputs (if any)", + ".OUTPUTS", + "\tOutput (if any)", + ".NOTES", + "\tGeneral notes", + "#>" + ] + }, + "Constructor": { + "prefix": "ctor", + "description": "Class constructor definition snippet", + "body": [ + "${1:ClassName}(${2:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "do-until": { + "prefix": "do-until", + "description": "do-until loop snippet", + "body": [ + "do {", + "\t${0:$TM_SELECTED_TEXT}", + "} until (${1:condition})" + ] + }, + "do-while": { + "prefix": "do-while", + "description": "do-while loop snippet", + "body": [ + "do {", + "\t${0:$TM_SELECTED_TEXT}", + "} while (${1:condition})" + ] + }, + "DSC Ensure Enum": { + "prefix": "DSC Ensure enum", + "description": "DSC Ensure enum definition snippet", + "body": [ + "enum Ensure {", + "\tAbsent", + "\tPresent", + "}" + ] + }, + "DSC Resource Provider (class-based)": { + "prefix": "DSC resource provider (class-based)", + "description": "Class-based DSC resource provider snippet", + "body": [ + "[DscResource()]", + "class ${ResourceName:NameOfResource} {", + "\t[DscProperty(Key)]", + "\t[string] $${PropertyName:KeyName}", + "\t", + "\t# Gets the resource's current state.", + "\t[${ResourceName:NameOfResource}] Get() {", + "\t\t${0:$TM_SELECTED_TEXT}", + "\t\treturn \\$this", + "\t}", + "\t", + "\t# Sets the desired state of the resource.", + "\t[void] Set() {", + "\t\t", + "\t}", + "\t", + "\t# Tests if the resource is in the desired state.", + "\t[bool] Test() {", + "\t\t", + "\t}", + "}" + ] + }, + "DSC Resource Provider (function-based)": { + "prefix": "DSC resource provider (function-based)", + "description": "Function-based DSC resource provider snippet", + "body": [ + "function Get-TargetResource {", + "\tparam (", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "function Set-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}", + "function Test-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}" + ] + }, + "else": { + "prefix": "else", + "description": "else statement snippet", + "body": [ + "else {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "elseif": { + "prefix": "elseif", + "description": "elseif statement snippet", + "body": [ + "elseif (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Enum": { + "prefix": "enum", + "description": "Enum definition snippet", + "body": [ + "enum ${1:EnumName} {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Example-Advanced Workflow": { + "prefix": "ex-advanced workflow", + "description": "Example: advanced workflow snippet", + "body": [ + "<#", + ".Synopsis", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tExample of how to use this workflow", + ".EXAMPLE", + "\tAnother example of how to use this workflow", + ".INPUTS", + "\tInputs to this workflow (if any)", + ".OUTPUTS", + "\tOutput from this workflow (if any)", + ".NOTES", + "\tGeneral notes", + ".FUNCTIONALITY", + "\tThe functionality that best describes this workflow", + "#>", + "workflow ${name:Verb-Noun} {", + "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", + "\t HelpUri = 'http://www.microsoft.com/',", + "\t ConfirmImpact='Medium')]", + "\t[Alias()]", + "\t[OutputType([String])]", + "\tparam (", + "\t\t# Param1 help description", + "\t\t[Parameter(Mandatory=\\$true, ", + "\t\t Position=0,", + "\t\t ParameterSetName='Parameter Set 1')]", + "\t\t[ValidateNotNull()]", + "\t\t[Alias(\"p1\")] ", + "\t\t\\$Param1,", + "", + "\t\t# Param2 help description", + "\t\t[int]", + "\t\t\\$Param2", + "\t)", + "", + "\t# Saves (persists) the current workflow state and output", + "\t# Checkpoint-Workflow", + "\t# Suspends the workflow", + "\t# Suspend-Workflow", + "", + "\t# Workflow common parameters are available as variables such as:", + "\t\\$PSPersist ", + "\t\\$PSComputerName", + "\t\\$PSCredential", + "\t\\$PSUseSsl", + "\t\\$PSAuthentication", + "", + "\t# Workflow runtime information can be accessed by using the following variables:", + "\t\\$Input", + "\t\\$PSSenderInfo", + "\t\\$PSWorkflowRoot", + "\t\\$JobCommandName", + "\t\\$ParentCommandName", + "\t\\$JobId", + "\t\\$ParentJobId", + "\t\\$WorkflowInstanceId", + "\t\\$JobInstanceId", + "\t\\$ParentJobInstanceId", + "\t\\$JobName", + "\t\\$ParentJobName", + "", + "\t# Set the progress message ParentActivityId", + "\t\\$PSParentActivityId", + "", + "\t# Preference variables that control runtime behavior", + "\t\\$PSRunInProcessPreference", + "\t\\$PSPersistPreference", + "}" + ] }, "Example-Class": { "prefix": "ex-class", + "description": "Example: class snippet with a constructor, property and a method", "body": [ "class ${1:MyClass} {", "\t# Property: Holds name", @@ -80,11 +291,11 @@ "\t\t\\$this.Name = \"DefaultName\"", "\t}", "}" - ], - "description": "Example: class snippet with a constructor, property and a method" + ] }, "Example-Cmdlet": { "prefix": "ex-cmdlet", + "description": "Example: script cmdlet snippet with all attributes and inline help fields", "body": [ "<#", ".SYNOPSIS", @@ -161,11 +372,11 @@ "\tend {", "\t}", "}" - ], - "description": "Example: script cmdlet snippet with all attributes and inline help fields" + ] }, "Example-DSC Configuration": { "prefix": "ex-DSC config", + "description": "Example: DSC configuration snippet that uses built-in resource providers", "body": [ "configuration Name {", "\t# One can evaluate expressions to get the node list", @@ -190,11 +401,11 @@ "\t\t}", "\t}", "}" - ], - "description": "Example: DSC configuration snippet that uses built-in resource providers" + ] }, "Example-DSC Resource Provider (class-based)": { "prefix": "ex-DSC resource provider (class-based)", + "description": "Example: class-based DSC resource provider snippet", "body": [ "# Defines the values for the resource's Ensure property.", "enum Ensure {", @@ -242,11 +453,11 @@ "\t\t return \\$true", "\t}", "}" - ], - "description": "Example: class-based DSC resource provider snippet" + ] }, "Example-DSC Resource Provider (function based)": { "prefix": "ex-DSC resource provider (function based)", + "description": "Example: function-based DSC resource provider snippet", "body": [ "function Get-TargetResource {", "\t# TODO: Add parameters here", @@ -269,15 +480,23 @@ "\tparam (", "\t)", "}" - ], - "description": "Example: function-based DSC resource provider snippet" + ] }, - "Example-Path Processing for Non-Existing Paths": { - "prefix": "ex-path processing for non-existing paths", + "Example-Path Processing for No Wildcards Allowed": { + "prefix": "ex-path processing for no wildcards allowed", + "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", "body": [ "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", "\\$paths = @()", "foreach (\\$aPath in \\$Path) {", + "\tif (!(Test-Path -LiteralPath \\$aPath)) {", + "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\tcontinue", + "\t}", + "", "\t# Resolve any relative paths", "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", "}", @@ -288,23 +507,15 @@ "\t\t$0", "\t}", "}" - ], - "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet." + ] }, - "Example-Path Processing for No Wildcards Allowed": { - "prefix": "ex-path processing for no wildcards allowed", + "Example-Path Processing for Non-Existing Paths": { + "prefix": "ex-path processing for non-existing paths", + "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", "body": [ "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", "\\$paths = @()", "foreach (\\$aPath in \\$Path) {", - "\tif (!(Test-Path -LiteralPath \\$aPath)) {", - "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\tcontinue", - "\t}", - "", "\t# Resolve any relative paths", "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", "}", @@ -315,11 +526,11 @@ "\t\t$0", "\t}", "}" - ], - "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets." + ] }, "Example-Path Processing for Wildcards Allowed": { "prefix": "ex-path processing for wildcards allowed", + "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", "body": [ "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", "\\$paths = @()", @@ -359,22 +570,22 @@ "\t\t$0", "\t}", "}" - ], - "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets." + ] }, "Example-Splatting": { "prefix": "ex-splat", + "description": "Example: PowerShell splatting technique snippet", "body": [ "\\$Params = @{", "\tModule = '*'", "\tVerb = 'Get'", "}", "Get-Command @Params" - ], - "description": "Example: PowerShell splatting technique snippet" + ] }, "Example-Switch": { "prefix": "ex-switch", + "description": "Example: switch statement snippet", "body": [ "switch (${variable:\\$x})", "{", @@ -383,141 +594,53 @@ "\t'value3' {}", "\tDefault {}", "}" - ], - "description": "Example: switch statement snippet" - }, - "Example-Advanced Workflow": { - "prefix": "ex-advanced workflow", - "body": [ - "<#", - ".Synopsis", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tExample of how to use this workflow", - ".EXAMPLE", - "\tAnother example of how to use this workflow", - ".INPUTS", - "\tInputs to this workflow (if any)", - ".OUTPUTS", - "\tOutput from this workflow (if any)", - ".NOTES", - "\tGeneral notes", - ".FUNCTIONALITY", - "\tThe functionality that best describes this workflow", - "#>", - "workflow ${name:Verb-Noun} {", - "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - "\t HelpUri = 'http://www.microsoft.com/',", - "\t ConfirmImpact='Medium')]", - "\t[Alias()]", - "\t[OutputType([String])]", - "\tparam (", - "\t\t# Param1 help description", - "\t\t[Parameter(Mandatory=\\$true, ", - "\t\t Position=0,", - "\t\t ParameterSetName='Parameter Set 1')]", - "\t\t[ValidateNotNull()]", - "\t\t[Alias(\"p1\")] ", - "\t\t\\$Param1,", - "", - "\t\t# Param2 help description", - "\t\t[int]", - "\t\t\\$Param2", - "\t)", - "", - "\t# Saves (persists) the current workflow state and output", - "\t# Checkpoint-Workflow", - "\t# Suspends the workflow", - "\t# Suspend-Workflow", - "", - "\t# Workflow common parameters are available as variables such as:", - "\t\\$PSPersist ", - "\t\\$PSComputerName", - "\t\\$PSCredential", - "\t\\$PSUseSsl", - "\t\\$PSAuthentication", - "", - "\t# Workflow runtime information can be accessed by using the following variables:", - "\t\\$Input", - "\t\\$PSSenderInfo", - "\t\\$PSWorkflowRoot", - "\t\\$JobCommandName", - "\t\\$ParentCommandName", - "\t\\$JobId", - "\t\\$ParentJobId", - "\t\\$WorkflowInstanceId", - "\t\\$JobInstanceId", - "\t\\$ParentJobInstanceId", - "\t\\$JobName", - "\t\\$ParentJobName", - "", - "\t# Set the progress message ParentActivityId", - "\t\\$PSParentActivityId", - "", - "\t# Preference variables that control runtime behavior", - "\t\\$PSRunInProcessPreference", - "\t\\$PSPersistPreference", - "}" - ], - "description": "Example: advanced workflow snippet" + ] }, - "Class": { - "prefix": "class", + "for": { + "prefix": "for", + "description": "for loop snippet", "body": [ - "class ${1:ClassName} {", + "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "Class definition snippet" + ] }, - "Constructor": { - "prefix": "ctor", + "for-reversed": { + "prefix": "forr", + "description": "reversed for loop snippet", "body": [ - "${1:ClassName}(${2:OptionalParameters}) {", + "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "Class constructor definition snippet" + ] }, - "Hidden Property": { - "prefix": "proph", - "body": [ - "hidden [${1:string}] $${0:PropertyName}" - ], - "description": "Class hidden property definition snippet" - }, - "Property": { - "prefix": "prop", - "body": [ - "[${1:string}] $${0:PropertyName}" - ], - "description": "Class property definition snippet" - }, - "Method": { - "prefix": "method", + "foreach": { + "prefix": "foreach", + "description": "foreach loop snippet", "body": [ - "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", + "foreach ($${1:item} in $${2:collection}) {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "Class method definition snippet" + ] }, - "Enum": { - "prefix": "enum", + "function": { + "prefix": "function", + "description": "Function definition snippet that contains a param block", "body": [ - "enum ${1:EnumName} {", + "function ${1:FunctionName} {", + "\tparam (", + "\t\t${2:OptionalParameters}", + "\t)", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "Enum definition snippet" + ] }, "Function-Advanced": { "prefix": [ "function-advanced", "cmdlet" ], + "description": "Script advanced function definition snippet", "body": [ "function ${1:Verb-Noun} {", "\t[CmdletBinding()]", @@ -537,32 +660,11 @@ "\t\t", "\t}", "}" - ], - "description": "Script advanced function definition snippet" - }, - "Comment-Help": { - "prefix": "comment-help", - "body": [ - "<#", - ".SYNOPSIS", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tPS C:\\> ", - "\tExplanation of what the example does", - ".INPUTS", - "\tInputs (if any)", - ".OUTPUTS", - "\tOutput (if any)", - ".NOTES", - "\tGeneral notes", - "#>" - ], - "description": "Comment-based help for an advanced function snippet" + ] }, "Function-Help": { "prefix": "help-function", + "description": "Comment-based help for an advanced function snippet", "body": [ "<#", ".SYNOPSIS", @@ -577,32 +679,187 @@ "\t${5:Test-MyTestFunction -Verbose}", "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", "#>" - ], - "description": "Comment-based help for an advanced function snippet" + ] + }, + "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", + "body": [ + "function ${1:FunctionName} (${2:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Hashtable": { + "prefix": "Hashtable", + "description": "Creates a Hashtable", + "body": [ + "\\$${1:Var} = @{", + "\t${2:Name} = ${3:Value}", + "}" + ] + }, + "Hidden Property": { + "prefix": "proph", + "description": "Class hidden property definition snippet", + "body": [ + "hidden [${1:string}] $${0:PropertyName}" + ] + }, + "IArgumentCompleter Class": { + "prefix": "completer-class", + "description": "IArgumentCompleter implementation class definition", + "body": [ + "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", + "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t) {", + "\t\t\\$CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()", + "\t\t", + "\t\t${0:$TM_SELECTED_TEXT}", + "\t\t", + "\t\treturn \\$CompletionResults", + "\t}", + "}" + ] + }, + "if": { + "prefix": "if", + "description": "if statement snippet", + "body": [ + "if (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "IfShouldProcess": { + "prefix": "IfShouldProcess", + "description": "Creates ShouldProcess block", + "body": [ + "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Method": { + "prefix": "method", + "description": "Class method definition snippet", + "body": [ + "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "ModuleManifest": { + "prefix": "manifest", + "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.", + "body": [ + "@{", + "\t# If authoring a script module, the RootModule is the name of your .psm1 file", + "\tRootModule = '${module:MyModule}.psm1'", + "", + "\tAuthor = '${author:Cool Person }'", + "", + "\tCompanyName = '${company:Contoso Inc.}'", + "", + "\tModuleVersion = '${ModuleVersion:0.1}'", + "", + "\t# Use the New-Guid command to generate a GUID, and copy/paste into the next line", + "\tGUID = ''", + "", + "\tCopyright = '2017 ${company:Copyright Holder}'", + "", + "\tDescription = '${Description:What does this module do?}'", + "", + "\t# Minimum PowerShell version supported by this module (optional, recommended)", + "\t# PowerShellVersion = ''", + "", + "\t# Which PowerShell Editions does this module work with? (Core, Desktop)", + "\tCompatiblePSEditions = @('Desktop', 'Core')", + "", + "\t# Which PowerShell functions are exported from your module? (eg. Get-CoolObject)", + "\tFunctionsToExport = @('')", + "", + "\t# Which PowerShell aliases are exported from your module? (eg. gco)", + "\tAliasesToExport = @('')", + "", + "\t# Which PowerShell variables are exported from your module? (eg. Fruits, Vegetables)", + "\tVariablesToExport = @('')", + "", + "\t# PowerShell Gallery: Define your module's metadata", + "\tPrivateData = @{", + "\t\tPSData = @{", + "\t\t\t# What keywords represent your PowerShell module? (eg. cloud, tools, framework, vendor)", + "\t\t\tTags = @('${tag1:cooltag1}', '${tag2:cooltag2}')", + "", + "\t\t\t# What software license is your code being released under? (see https://opensource.org/licenses)", + "\t\t\tLicenseUri = ''", + "", + "\t\t\t# What is the URL to your project's website?", + "\t\t\tProjectUri = ''", + "", + "\t\t\t# What is the URI to a custom icon file for your project? (optional)", + "\t\t\tIconUri = ''", + "", + "\t\t\t# What new features, bug fixes, or deprecated features, are part of this release?", + "\t\t\tReleaseNotes = @'", + "'@", + "\t\t}", + "\t}", + "", + "\t# If your module supports updateable help, what is the URI to the help archive? (optional)", + "\t# HelpInfoURI = ''", + "}" + ] }, "Parameter": { "prefix": "parameter", + "description": "Parameter declaration snippet", "body": [ "# ${1:Parameter help description}", "[Parameter(${2:AttributeValues})]", "[${3:ParameterType}]", "$${0:ParameterName}" - ], - "description": "Parameter declaration snippet" + ] }, - "Parameter_Block" : { + "Parameter_Block": { "prefix": "param-block", - "body": ["[CmdletBinding()]", + "description": "A Parameter block to get you started.", + "body": [ + "[CmdletBinding()]", "param (", " [Parameter()]", " [${1:TypeName}]", " $${2:ParameterName}$0", ")" - ], - "description": "A Parameter block to get you started." + ] + }, + "Parameter-LiteralPath": { + "prefix": "parameter-literalpath", + "description": "Parameter declaration snippet for a LiteralPath parameter", + "body": [ + "# Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is", + "# used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters,", + "# enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any", + "# characters as escape sequences.", + "[Parameter(Mandatory=\\$true,", + " Position=${1:0},", + " ParameterSetName=\"${2:LiteralPath}\",", + " ValueFromPipelineByPropertyName=\\$true,", + " HelpMessage=\"Literal path to one or more locations.\")]", + "[Alias(\"PSPath\")]", + "[ValidateNotNullOrEmpty()]", + "[string[]]", + "$${2:LiteralPath}$0" + ] }, "Parameter-Path": { "prefix": "parameter-path", + "description": "Parameter declaration snippet for Path parameter that does not accept wildcards. Do not use with parameter-literalpath.", "body": [ "# Specifies a path to one or more locations.", "[Parameter(Mandatory=\\$true,", @@ -615,11 +872,11 @@ "[ValidateNotNullOrEmpty()]", "[string[]]", "$${3:ParameterName}$0" - ], - "description": "Parameter declaration snippet for Path parameter that does not accept wildcards. Do not use with parameter-literalpath." + ] }, "Parameter-Path-Wildcards": { "prefix": "parameter-path-wildcards", + "description": "Parameter declaration snippet for Path parameter that accepts wildcards. Add parameter-literalpath to handle paths with embedded wildcard chars.", "body": [ "# Specifies a path to one or more locations. Wildcards are permitted.", "[Parameter(Mandatory=\\$true,", @@ -632,210 +889,178 @@ "[SupportsWildcards()]", "[string[]]", "$${3:ParameterName}$0" - ], - "description": "Parameter declaration snippet for Path parameter that accepts wildcards. Add parameter-literalpath to handle paths with embedded wildcard chars." + ] }, - "Parameter-LiteralPath": { - "prefix": "parameter-literalpath", - "body": [ - "# Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is", - "# used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters,", - "# enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any", - "# characters as escape sequences.", - "[Parameter(Mandatory=\\$true,", - " Position=${1:0},", - " ParameterSetName=\"${2:LiteralPath}\",", - " ValueFromPipelineByPropertyName=\\$true,", - " HelpMessage=\"Literal path to one or more locations.\")]", - "[Alias(\"PSPath\")]", - "[ValidateNotNullOrEmpty()]", - "[string[]]", - "$${2:LiteralPath}$0" - ], - "description": "Parameter declaration snippet for a LiteralPath parameter" - }, - "DSC Ensure Enum": { - "prefix": "DSC Ensure enum", + "PesterContext": { + "prefix": "Context-Pester", + "description": "Pester - Context block", "body": [ - "enum Ensure {", - "\tAbsent", - "\tPresent", + "Context \"${1:ContextName}\" {", + "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "DSC Ensure enum definition snippet" + ] }, - "DSC Resource Provider (class-based)": { - "prefix": "DSC resource provider (class-based)", + "PesterContextIt": { + "prefix": "Context-It-Pester", + "description": "Pester - Context block with nested It block", "body": [ - "[DscResource()]", - "class ${ResourceName:NameOfResource} {", - "\t[DscProperty(Key)]", - "\t[string] $${PropertyName:KeyName}", - "\t", - "\t# Gets the resource's current state.", - "\t[${ResourceName:NameOfResource}] Get() {", - "\t\t${0:$TM_SELECTED_TEXT}", - "\t\treturn \\$this", - "\t}", - "\t", - "\t# Sets the desired state of the resource.", - "\t[void] Set() {", - "\t\t", - "\t}", - "\t", - "\t# Tests if the resource is in the desired state.", - "\t[bool] Test() {", - "\t\t", - "\t}", + "Context \"${1:ContextName}\" {", + "\tIt \"${2:ItName}\" {", + "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", + "\t}$0", "}" - ], - "description": "Class-based DSC resource provider snippet" + ] }, - "DSC Resource Provider (function-based)": { - "prefix": "DSC resource provider (function-based)", + "PesterDescribeBlock": { + "prefix": "Describe-Pester", + "description": "Pester Describe block", "body": [ - "function Get-TargetResource {", - "\tparam (", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "function Set-TargetResource {", - "\tparam (", - "\t)", - "\t", - "}", - "function Test-TargetResource {", - "\tparam (", - "\t)", - "\t", + "Describe \"${1:DescribeName}\" {", + "\t${0:TM_SELECTED_TEXT}", "}" - ], - "description": "Function-based DSC resource provider snippet" + ] }, - "comment block": { - "prefix": "comment", + "PesterDescribeContextIt": { + "prefix": "Describe-Context-It-Pester", + "description": "Pester Describe block with nested Context & It blocks", "body": [ - "<#", - " # ${0:$TM_SELECTED_TEXT}", - " #>" - ], - "description": "Comment block snippet" + "Describe \"${1:DescribeName}\" {", + "\tContext \"${2:ContextName}\" {", + "\t\tIt \"${3:ItName}\" {", + "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", + "\t\t}$0", + "\t}", + "}" + ] }, - "do-until": { - "prefix": "do-until", + "PesterIt": { + "prefix": "It-Pester", + "description": "Pester - It block", "body": [ - "do {", - "\t${0:$TM_SELECTED_TEXT}", - "} until (${1:condition})" - ], - "description": "do-until loop snippet" + "It \"${1:ItName}\" {", + "\t${2:${TM_SELECTED_TEXT:Assertion}}", + "}$0" + ] }, - "do-while": { - "prefix": "do-while", + "Property": { + "prefix": "prop", + "description": "Class property definition snippet", "body": [ - "do {", - "\t${0:$TM_SELECTED_TEXT}", - "} while (${1:condition})" - ], - "description": "do-while loop snippet" + "[${1:string}] $${0:PropertyName}" + ] }, - "while": { - "prefix": "while", + "PSCustomObject": { + "prefix": "[PSCustomObject]", + "description": "Creates a PSCustomObject", "body": [ - "while (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", + "[PSCustomObject]@{", + "\t${1:Name} = ${2:Value}", "}" - ], - "description": "while loop snippet" + ] }, - "for": { - "prefix": "for", + "Region Block": { + "prefix": "#region", + "description": "Region Block for organizing and folding of your code", "body": [ - "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "for loop snippet" + "#region ${1}", + "${0:$TM_SELECTED_TEXT}", + "#endregion" + ] + }, + "Requires Assembly": { + "prefix": "requires-assembly", + "description": "Requires an assembly (by name) in order to execute the containing script file.", + "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'" + }, + "Requires Assembly Path": { + "prefix": "requires-assembly-path", + "description": "Requires an assembly (by relative or absolute path) in order to execute the containing script file.", + "body": "#Requires -Assembly ${0:${TM_SELECTED_TEXT:path/to/assembly.dll}}" + }, + "Requires Assembly Version": { + "prefix": "requires-assembly-version", + "description": "Requires an assembly (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}, Version=${2:1.0.0.0}'" + }, + "Requires Module": { + "prefix": "requires-module", + "description": "Requires a module (by name) in order to execute the containing script file.", + "body": "#Requires -Module ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" + }, + "Requires Module RequiredVersion": { + "prefix": "requires-module-required-version", + "description": "Requires a module (by name and exact version) in order to execute the containing script file.", + "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; RequiredVersion = '${2:exact-required-version}' }" + }, + "Requires Module Version": { + "prefix": "requires-module-version", + "description": "Requires a module (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; ModuleVersion = '${2:minimum-acceptable-version}' }" + }, + "Requires PSEdition": { + "prefix": "requires-ps-edition", + "description": "Requires a specific edition of PowerShell in order to execute the containing script file.", + "body": "#Requires -PSEdition ${1|Core,Desktop|}" + }, + "Requires PSSnapin": { + "prefix": "requires-ps-snapin", + "description": "Requires a PowerShell snap-in (by name) in order to execute the containing script file.", + "body": "#Requires -PSSnapin ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" }, - "for-reversed": { - "prefix": "forr", - "body": [ - "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "reversed for loop snippet" + "Requires PSSnapin Version": { + "prefix": "requires-ps-snapin-version", + "description": "Requires a PowerShell snap-in (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -PSSnapin ${1:${TM_SELECTED_TEXT:fully-qualified-name}} -Version ${2:minimum-acceptable-version}" }, - "foreach": { - "prefix": "foreach", - "body": [ - "foreach ($${1:item} in $${2:collection}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "foreach loop snippet" + "Requires RunAsAdministrator": { + "prefix": "requires-run-as-administrator", + "description": "Requires elevated user rights in order to execute the containing script file. Ignored on non-Windows systems. On Windows systems, it requires that the PowerShell session in which the containing script file is run must have been started with elevated user rights (\"Run as Administrator\").", + "body": "#Requires -RunAsAdministrator" }, - "function": { - "prefix": "function", - "body": [ - "function ${1:FunctionName} {", - "\tparam (", - "\t\t${2:OptionalParameters}", - "\t)", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "Function definition snippet that contains a param block" + "Requires ShellId": { + "prefix": "requires-shell-id", + "description": "Requires a specific shell id in order to execute the containing script file. The current shell id may be determined by querying the $ShellId automatic variable.", + "body": "#Requires -ShellId ${0:${TM_SELECTED_TEXT:shell-id}}" }, - "Function-Inline": { - "prefix": "Function-Inline", - "body": [ - "function ${1:FunctionName} (${2:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "Function definition snippet that does not contain a param block, but defines parameters inline. This syntax is commonly used in other languages" + "Requires Version": { + "prefix": "requires-version", + "description": "Requires a minimum version of PowerShell in order to execute the containing script file.", + "body": "#Requires -Version ${0:${TM_SELECTED_TEXT:minimum-acceptable-version}}" }, - "if": { - "prefix": "if", + "Suppress PSScriptAnalyzer Rule": { + "prefix": "suppress-message-rule", + "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", "body": [ - "if (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "if statement snippet" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" + ] }, - "elseif": { - "prefix": "elseif", + "Suppress PSScriptAnalyzer Rule in Scope": { + "prefix": "suppress-message-rule-for-scope", + "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", "body": [ - "elseif (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "elseif statement snippet" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" + ] }, - "else": { - "prefix": "else", + "Suppress PSScriptAnalyzer Rule on Parameter": { + "prefix": "suppress-message-rule-for-parameter", + "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", "body": [ - "else {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "else statement snippet" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" + ] }, "switch": { "prefix": "switch", + "description": "switch statement snippet", "body": [ "switch (${1:\\$x}) {", "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }", "\tDefault {}", "}" - ], - "description": "switch statement snippet" + ] }, "try-catch": { "prefix": "try", + "description": "try-catch snippet", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", @@ -843,11 +1068,11 @@ "catch {", "\t", "}" - ], - "description": "try-catch snippet" + ] }, "try-catch-finally": { "prefix": "trycf", + "description": "try-catch-finally snippet", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", @@ -858,11 +1083,11 @@ "finally {", "\t", "}" - ], - "description": "try-catch-finally snippet" + ] }, "try-finally": { "prefix": "tryf", + "description": "try-finally snippet", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", @@ -870,11 +1095,20 @@ "finally {", "\t", "}" - ], - "description": "try-finally snippet" + ] + }, + "while": { + "prefix": "while", + "description": "while loop snippet", + "body": [ + "while (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] }, "Workflow": { "prefix": "workflow", + "description": "workflow snippet", "body": [ "workflow ${name:Verb-Noun} {", "\tparam (", @@ -882,275 +1116,42 @@ "", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "workflow snippet" + ] }, "Workflow ForEachParallel": { "prefix": "workflow foreach-parallel", + "description": "foreach-parallel snippet (for use inside a workflow)", "body": [ "foreach -parallel ($${variable:item} in $${collection:collection}) {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "foreach-parallel snippet (for use inside a workflow)" + ] }, "Workflow InlineScript": { "prefix": "workflow inlinescript", + "description": "inlinescript snippet (for use inside a workflow)", "body": [ "inlineScript {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "inlinescript snippet (for use inside a workflow)" + ] }, "Workflow Parallel": { "prefix": "workflow parallel", + "description": "parallel snippet (for use inside a workflow)", "body": [ "parallel {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "parallel snippet (for use inside a workflow)" + ] }, "Workflow Sequence": { "prefix": "workflow sequence", + "description": "sequence snippet (for use inside a workflow)", "body": [ "sequence {", "\t${0:$TM_SELECTED_TEXT}", "}" - ], - "description": "sequence snippet (for use inside a workflow)" - }, - "Suppress PSScriptAnalyzer Rule": { - "prefix": "suppress-message-rule", - "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" - ] - }, - "Suppress PSScriptAnalyzer Rule on Parameter": { - "prefix": "suppress-message-rule-for-parameter", - "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" - ] - }, - "Suppress PSScriptAnalyzer Rule in Scope": { - "prefix": "suppress-message-rule-for-scope", - "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" - ] - }, - "PSCustomObject": { - "prefix": "[PSCustomObject]", - "body": [ - "[PSCustomObject]@{", - "\t${1:Name} = ${2:Value}", - "}" - ], - "description": "Creates a PSCustomObject" - }, - "Hashtable": { - "prefix": "Hashtable", - "body": [ - "\\$${1:Var} = @{", - "\t${2:Name} = ${3:Value}", - "}" - ], - "description": "Creates a Hashtable" - }, - "Region Block": { - "prefix": "#region", - "body": [ - "#region ${1}", - "${0:$TM_SELECTED_TEXT}", - "#endregion" - ], - "description": "Region Block for organizing and folding of your code" - }, - "IfShouldProcess": { - "prefix": "IfShouldProcess", - "body": [ - "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "Creates ShouldProcess block" - }, - "CalculatedProperty": { - "prefix": "Calculated-Property", - "body": [ - "@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" - ], - "description": "Creates a Calculated Property typically used with Select-Object." - }, - "PesterDescribeContextIt": { - "prefix": "Describe-Context-It-Pester", - "body": [ - "Describe \"${1:DescribeName}\" {", - "\tContext \"${2:ContextName}\" {", - "\t\tIt \"${3:ItName}\" {", - "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", - "\t\t}$0", - "\t}", - "}" - ], - "description": "Pester Describe block with nested Context & It blocks" - }, - "PesterDescribeBlock": { - "prefix": "Describe-Pester", - "body": [ - "Describe \"${1:DescribeName}\" {", - "\t${0:TM_SELECTED_TEXT}", - "}" - ], - "description": "Pester Describe block" - }, - "PesterContextIt": { - "prefix": "Context-It-Pester", - "body": [ - "Context \"${1:ContextName}\" {", - "\tIt \"${2:ItName}\" {", - "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", - "\t}$0", - "}" - ], - "description": "Pester - Context block with nested It block" - }, - "PesterContext": { - "prefix": "Context-Pester", - "body": [ - "Context \"${1:ContextName}\" {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "Pester - Context block" - }, - "PesterIt": { - "prefix": "It-Pester", - "body": [ - "It \"${1:ItName}\" {", - "\t${2:${TM_SELECTED_TEXT:Assertion}}", - "}$0" - ], - "description": "Pester - It block" - }, - "ArgumentCompleterAttribute with ScriptBlock": { - "prefix": "completer-attribute", - "body": [ - "[ArgumentCompleter({", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", - "\tparam(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "})]" - ], - "description": "ArgumentCompleter parameter attribute with script block definition" - }, - "ArgumentCompleterAttribute ScriptBlock": { - "prefix": "completer-scriptblock", - "body": [ - "{", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", - "\tparam(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ], - "description": "ArgumentCompleter parameter attribute script block definition" - }, - "IArgumentCompleter Class": { - "prefix": "completer-class", - "body": [ - "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", - "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t) {", - "\t\t\\$CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()", - "\t\t", - "\t\t${0:$TM_SELECTED_TEXT}", - "\t\t", - "\t\treturn \\$CompletionResults", - "\t}", - "}" - ], - "description": "IArgumentCompleter implementation class definition" - }, - "Requires Assembly": { - "prefix": "requires-assembly", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'", - "description": "Requires an assembly (by name) in order to execute the containing script file." - }, - "Requires Assembly Path": { - "prefix": "requires-assembly-path", - "body": "#Requires -Assembly ${0:${TM_SELECTED_TEXT:path/to/assembly.dll}}", - "description": "Requires an assembly (by relative or absolute path) in order to execute the containing script file." - }, - "Requires Assembly Version": { - "prefix": "requires-assembly-version", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}, Version=${2:1.0.0.0}'", - "description": "Requires an assembly (by name and minimum version) in order to execute the containing script file." - }, - "Requires Module": { - "prefix": "requires-module", - "body": "#Requires -Module ${0:${TM_SELECTED_TEXT:fully-qualified-name}}", - "description": "Requires a module (by name) in order to execute the containing script file." - }, - "Requires Module RequiredVersion": { - "prefix": "requires-module-required-version", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; RequiredVersion = '${2:exact-required-version}' }", - "description": "Requires a module (by name and exact version) in order to execute the containing script file." - }, - "Requires Module Version": { - "prefix": "requires-module-version", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; ModuleVersion = '${2:minimum-acceptable-version}' }", - "description": "Requires a module (by name and minimum version) in order to execute the containing script file." - }, - "Requires PSEdition": { - "prefix": "requires-ps-edition", - "body": "#Requires -PSEdition ${1|Core,Desktop|}", - "description": "Requires a specific edition of PowerShell in order to execute the containing script file." - }, - "Requires PSSnapin": { - "prefix": "requires-ps-snapin", - "body": "#Requires -PSSnapin ${0:${TM_SELECTED_TEXT:fully-qualified-name}}", - "description": "Requires a PowerShell snap-in (by name) in order to execute the containing script file." - }, - "Requires PSSnapin Version": { - "prefix": "requires-ps-snapin-version", - "body": "#Requires -PSSnapin ${1:${TM_SELECTED_TEXT:fully-qualified-name}} -Version ${2:minimum-acceptable-version}", - "description": "Requires a PowerShell snap-in (by name and minimum version) in order to execute the containing script file." - }, - "Requires RunAsAdministrator": { - "prefix": "requires-run-as-administrator", - "body": "#Requires -RunAsAdministrator", - "description": "Requires elevated user rights in order to execute the containing script file. Ignored on non-Windows systems. On Windows systems, it requires that the PowerShell session in which the containing script file is run must have been started with elevated user rights (\"Run as Administrator\")." - }, - "Requires ShellId": { - "prefix": "requires-shell-id", - "body": "#Requires -ShellId ${0:${TM_SELECTED_TEXT:shell-id}}", - "description": "Requires a specific shell id in order to execute the containing script file. The current shell id may be determined by querying the $ShellId automatic variable." - }, - "Requires Version": { - "prefix": "requires-version", - "body": "#Requires -Version ${0:${TM_SELECTED_TEXT:minimum-acceptable-version}}", - "description": "Requires a minimum version of PowerShell in order to execute the containing script file." + ] } } From 4d897ba8f9b372e7dd06347698e6f99927dafba9 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 09:33:31 -0800 Subject: [PATCH 03/14] Fix format indent --- snippets/PowerShell.json | 2308 +++++++++++++++++++------------------- 1 file changed, 1154 insertions(+), 1154 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 04d6290213..42a5dccc8f 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,1157 +1,1157 @@ // The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { - "ArgumentCompleterAttribute ScriptBlock": { - "prefix": "completer-scriptblock", - "description": "ArgumentCompleter parameter attribute script block definition", - "body": [ - "{", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", - "\tparam(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "ArgumentCompleterAttribute with ScriptBlock": { - "prefix": "completer-attribute", - "description": "ArgumentCompleter parameter attribute with script block definition", - "body": [ - "[ArgumentCompleter({", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", - "\tparam(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "})]" - ] - }, - "CalculatedProperty": { - "prefix": "Calculated-Property", - "description": "Creates a Calculated Property typically used with Select-Object.", - "body": [ - "@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" - ] - }, - "Class": { - "prefix": "class", - "description": "Class definition snippet", - "body": [ - "class ${1:ClassName} {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "comment block": { - "prefix": "comment", - "description": "Comment block snippet", - "body": [ - "<#", - " # ${0:$TM_SELECTED_TEXT}", - " #>" - ] - }, - "Comment-Help": { - "prefix": "comment-help", - "description": "Comment-based help for an advanced function snippet", - "body": [ - "<#", - ".SYNOPSIS", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tPS C:\\> ", - "\tExplanation of what the example does", - ".INPUTS", - "\tInputs (if any)", - ".OUTPUTS", - "\tOutput (if any)", - ".NOTES", - "\tGeneral notes", - "#>" - ] - }, - "Constructor": { - "prefix": "ctor", - "description": "Class constructor definition snippet", - "body": [ - "${1:ClassName}(${2:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "do-until": { - "prefix": "do-until", - "description": "do-until loop snippet", - "body": [ - "do {", - "\t${0:$TM_SELECTED_TEXT}", - "} until (${1:condition})" - ] - }, - "do-while": { - "prefix": "do-while", - "description": "do-while loop snippet", - "body": [ - "do {", - "\t${0:$TM_SELECTED_TEXT}", - "} while (${1:condition})" - ] - }, - "DSC Ensure Enum": { - "prefix": "DSC Ensure enum", - "description": "DSC Ensure enum definition snippet", - "body": [ - "enum Ensure {", - "\tAbsent", - "\tPresent", - "}" - ] - }, - "DSC Resource Provider (class-based)": { - "prefix": "DSC resource provider (class-based)", - "description": "Class-based DSC resource provider snippet", - "body": [ - "[DscResource()]", - "class ${ResourceName:NameOfResource} {", - "\t[DscProperty(Key)]", - "\t[string] $${PropertyName:KeyName}", - "\t", - "\t# Gets the resource's current state.", - "\t[${ResourceName:NameOfResource}] Get() {", - "\t\t${0:$TM_SELECTED_TEXT}", - "\t\treturn \\$this", - "\t}", - "\t", - "\t# Sets the desired state of the resource.", - "\t[void] Set() {", - "\t\t", - "\t}", - "\t", - "\t# Tests if the resource is in the desired state.", - "\t[bool] Test() {", - "\t\t", - "\t}", - "}" - ] - }, - "DSC Resource Provider (function-based)": { - "prefix": "DSC resource provider (function-based)", - "description": "Function-based DSC resource provider snippet", - "body": [ - "function Get-TargetResource {", - "\tparam (", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "function Set-TargetResource {", - "\tparam (", - "\t)", - "\t", - "}", - "function Test-TargetResource {", - "\tparam (", - "\t)", - "\t", - "}" - ] - }, - "else": { - "prefix": "else", - "description": "else statement snippet", - "body": [ - "else {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "elseif": { - "prefix": "elseif", - "description": "elseif statement snippet", - "body": [ - "elseif (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Enum": { - "prefix": "enum", - "description": "Enum definition snippet", - "body": [ - "enum ${1:EnumName} {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Example-Advanced Workflow": { - "prefix": "ex-advanced workflow", - "description": "Example: advanced workflow snippet", - "body": [ - "<#", - ".Synopsis", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tExample of how to use this workflow", - ".EXAMPLE", - "\tAnother example of how to use this workflow", - ".INPUTS", - "\tInputs to this workflow (if any)", - ".OUTPUTS", - "\tOutput from this workflow (if any)", - ".NOTES", - "\tGeneral notes", - ".FUNCTIONALITY", - "\tThe functionality that best describes this workflow", - "#>", - "workflow ${name:Verb-Noun} {", - "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - "\t HelpUri = 'http://www.microsoft.com/',", - "\t ConfirmImpact='Medium')]", - "\t[Alias()]", - "\t[OutputType([String])]", - "\tparam (", - "\t\t# Param1 help description", - "\t\t[Parameter(Mandatory=\\$true, ", - "\t\t Position=0,", - "\t\t ParameterSetName='Parameter Set 1')]", - "\t\t[ValidateNotNull()]", - "\t\t[Alias(\"p1\")] ", - "\t\t\\$Param1,", - "", - "\t\t# Param2 help description", - "\t\t[int]", - "\t\t\\$Param2", - "\t)", - "", - "\t# Saves (persists) the current workflow state and output", - "\t# Checkpoint-Workflow", - "\t# Suspends the workflow", - "\t# Suspend-Workflow", - "", - "\t# Workflow common parameters are available as variables such as:", - "\t\\$PSPersist ", - "\t\\$PSComputerName", - "\t\\$PSCredential", - "\t\\$PSUseSsl", - "\t\\$PSAuthentication", - "", - "\t# Workflow runtime information can be accessed by using the following variables:", - "\t\\$Input", - "\t\\$PSSenderInfo", - "\t\\$PSWorkflowRoot", - "\t\\$JobCommandName", - "\t\\$ParentCommandName", - "\t\\$JobId", - "\t\\$ParentJobId", - "\t\\$WorkflowInstanceId", - "\t\\$JobInstanceId", - "\t\\$ParentJobInstanceId", - "\t\\$JobName", - "\t\\$ParentJobName", - "", - "\t# Set the progress message ParentActivityId", - "\t\\$PSParentActivityId", - "", - "\t# Preference variables that control runtime behavior", - "\t\\$PSRunInProcessPreference", - "\t\\$PSPersistPreference", - "}" - ] - }, - "Example-Class": { - "prefix": "ex-class", - "description": "Example: class snippet with a constructor, property and a method", - "body": [ - "class ${1:MyClass} {", - "\t# Property: Holds name", - "\t[String] \\$Name", - "", - "\t# Constructor: Creates a new MyClass object, with the specified name", - "\t${1:MyClass}([String] \\$NewName) {", - "\t\t# Set name for ${1:MyClass}", - "\t\t\\$this.Name = \\$NewName", - "\t}", - "", - "\t# Method: Method that changes \\$Name to the default name", - "\t[void] ChangeNameToDefault() {", - "\t\t\\$this.Name = \"DefaultName\"", - "\t}", - "}" - ] - }, - "Example-Cmdlet": { - "prefix": "ex-cmdlet", - "description": "Example: script cmdlet snippet with all attributes and inline help fields", - "body": [ - "<#", - ".SYNOPSIS", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tExample of how to use this cmdlet", - ".EXAMPLE", - "\tAnother example of how to use this cmdlet", - ".INPUTS", - "\tInputs to this cmdlet (if any)", - ".OUTPUTS", - "\tOutput from this cmdlet (if any)", - ".NOTES", - "\tGeneral notes", - ".COMPONENT", - "\tThe component this cmdlet belongs to", - ".ROLE", - "\tThe role this cmdlet belongs to", - ".FUNCTIONALITY", - "\tThe functionality that best describes this cmdlet", - "#>", - "function ${name:Verb-Noun} {", - "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - "\t SupportsShouldProcess=\\$true,", - "\t PositionalBinding=\\$false,", - "\t HelpUri = 'http://www.microsoft.com/',", - "\t ConfirmImpact='Medium')]", - "\t[Alias()]", - "\t[OutputType([String])]", - "\tParam (", - "\t\t# Param1 help description", - "\t\t[Parameter(Mandatory=\\$true,", - "\t\t Position=0,", - "\t\t ValueFromPipeline=\\$true,", - "\t\t ValueFromPipelineByPropertyName=\\$true,", - "\t\t ValueFromRemainingArguments=\\$false, ", - "\t\t ParameterSetName='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", - "\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", - "\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", - "\tbegin {", - "\t}", - "\t", - "\tprocess {", - "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", - "\t\t\t$0", - "\t\t}", - "\t}", - "\t", - "\tend {", - "\t}", - "}" - ] - }, - "Example-DSC Configuration": { - "prefix": "ex-DSC config", - "description": "Example: DSC configuration snippet that uses built-in resource providers", - "body": [ - "configuration Name {", - "\t# One can evaluate expressions to get the node list", - "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", - "\tnode (\"Node1\",\"Node2\",\"Node3\")", - "\t{", - "\t\t# Call Resource Provider", - "\t\t# E.g: WindowsFeature, File", - "\t\tWindowsFeature FriendlyName", - "\t\t{", - "\t\t\tEnsure = \"Present\"", - "\t\t\tName = \"Feature Name\"", - "\t\t}", - "", - "\t\tFile FriendlyName", - "\t\t{", - "\t\t\tEnsure = \"Present\"", - "\t\t\tSourcePath = \\$SourcePath", - "\t\t\tDestinationPath = \\$DestinationPath", - "\t\t\tType = \"Directory\"", - "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", - "\t\t}", - "\t}", - "}" - ] - }, - "Example-DSC Resource Provider (class-based)": { - "prefix": "ex-DSC resource provider (class-based)", - "description": "Example: class-based DSC resource provider snippet", - "body": [ - "# Defines the values for the resource's Ensure property.", - "enum Ensure {", - "\t# The resource must be absent.", - "\tAbsent", - "\t# The resource must be present.", - "\tPresent", - "}", - "", - "# [DscResource()] indicates the class is a DSC resource.", - "[DscResource()]", - "class NameOfResource {", - "\t# A DSC resource must define at least one key property.", - "\t[DscProperty(Key)]", - "\t[string] \\$P1", - "\t", - "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", - "\t[DscProperty(Mandatory)]", - "\t[Ensure] \\$P2", - "\t", - "\t# NotConfigurable properties return additional information about the state of the resource.", - "\t# For example, a Get() method might return the date a resource was last modified.", - "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", - "\t[DscProperty(NotConfigurable)]", - "\t[Nullable[datetime]] \\$P3", - "\t", - "\t[DscProperty()]", - "\t[ValidateSet(\"val1\", \"val2\")]", - "\t[string] \\$P4", - "\t", - "\t# Gets the resource's current state.", - "\t[NameOfResource] Get() {", - "\t\t# NotConfigurable properties are set in the Get method.", - "\t\t\\$this.P3 = something", - "\t\t# Return this instance or construct a new instance.", - "\t\treturn \\$this", - "\t}", - "\t", - "\t# Sets the desired state of the resource.", - "\t[void] Set() {", - "\t}", - "\t", - "\t# Tests if the resource is in the desired state.", - "\t[bool] Test() {", - "\t\t return \\$true", - "\t}", - "}" - ] - }, - "Example-DSC Resource Provider (function based)": { - "prefix": "ex-DSC resource provider (function based)", - "description": "Example: function-based DSC resource provider snippet", - "body": [ - "function Get-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}", - "function Set-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}", - "function Test-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}" - ] - }, - "Example-Path Processing for No Wildcards Allowed": { - "prefix": "ex-path processing for no wildcards allowed", - "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - "\\$paths = @()", - "foreach (\\$aPath in \\$Path) {", - "\tif (!(Test-Path -LiteralPath \\$aPath)) {", - "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\tcontinue", - "\t}", - "", - "\t# Resolve any relative paths", - "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Path Processing for Non-Existing Paths": { - "prefix": "ex-path processing for non-existing paths", - "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - "\\$paths = @()", - "foreach (\\$aPath in \\$Path) {", - "\t# Resolve any relative paths", - "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Path Processing for Wildcards Allowed": { - "prefix": "ex-path processing for wildcards allowed", - "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", - "\\$paths = @()", - "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", - "\tforeach (\\$aPath in \\$Path) {", - "\t\tif (!(Test-Path -Path \\$aPath)) {", - "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\t\tcontinue", - "\t\t}", - "\t", - "\t\t# Resolve any wildcards that might be in the path", - "\t\t\\$provider = \\$null", - "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", - "\t}", - "}", - "else {", - "\tforeach (\\$aPath in \\$LiteralPath) {", - "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", - "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\t\tcontinue", - "\t\t}", - "\t", - "\t\t# Resolve any relative paths", - "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "\t}", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Splatting": { - "prefix": "ex-splat", - "description": "Example: PowerShell splatting technique snippet", - "body": [ - "\\$Params = @{", - "\tModule = '*'", - "\tVerb = 'Get'", - "}", - "Get-Command @Params" - ] - }, - "Example-Switch": { - "prefix": "ex-switch", - "description": "Example: switch statement snippet", - "body": [ - "switch (${variable:\\$x})", - "{", - "\t'${val:value1}' { $1 }", - "\t{\\$_ -in 'A','B','C'} {}", - "\t'value3' {}", - "\tDefault {}", - "}" - ] - }, - "for": { - "prefix": "for", - "description": "for loop snippet", - "body": [ - "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "for-reversed": { - "prefix": "forr", - "description": "reversed for loop snippet", - "body": [ - "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "foreach": { - "prefix": "foreach", - "description": "foreach loop snippet", - "body": [ - "foreach ($${1:item} in $${2:collection}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "function": { - "prefix": "function", - "description": "Function definition snippet that contains a param block", - "body": [ - "function ${1:FunctionName} {", - "\tparam (", - "\t\t${2:OptionalParameters}", - "\t)", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Function-Advanced": { - "prefix": [ - "function-advanced", - "cmdlet" - ], - "description": "Script advanced function definition snippet", - "body": [ - "function ${1:Verb-Noun} {", - "\t[CmdletBinding()]", - "\tparam (", - "\t\t$0", - "\t)", - "\t", - "\tbegin {", - "\t\t", - "\t}", - "\t", - "\tprocess {", - "\t\t$TM_SELECTED_TEXT", - "\t}", - "\t", - "\tend {", - "\t\t", - "\t}", - "}" - ] - }, - "Function-Help": { - "prefix": "help-function", - "description": "Comment-based help for an advanced function snippet", - "body": [ - "<#", - ".SYNOPSIS", - "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", - ".DESCRIPTION", - "\t${2:A longer description of the function, its purpose, common use cases, etc.}", - ".NOTES", - "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", - ".LINK", - "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", - ".EXAMPLE", - "\t${5:Test-MyTestFunction -Verbose}", - "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", - "#>" - ] - }, - "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", - "body": [ - "function ${1:FunctionName} (${2:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Hashtable": { - "prefix": "Hashtable", - "description": "Creates a Hashtable", - "body": [ - "\\$${1:Var} = @{", - "\t${2:Name} = ${3:Value}", - "}" - ] - }, - "Hidden Property": { - "prefix": "proph", - "description": "Class hidden property definition snippet", - "body": [ - "hidden [${1:string}] $${0:PropertyName}" - ] - }, - "IArgumentCompleter Class": { - "prefix": "completer-class", - "description": "IArgumentCompleter implementation class definition", - "body": [ - "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", - "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t) {", - "\t\t\\$CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()", - "\t\t", - "\t\t${0:$TM_SELECTED_TEXT}", - "\t\t", - "\t\treturn \\$CompletionResults", - "\t}", - "}" - ] - }, - "if": { - "prefix": "if", - "description": "if statement snippet", - "body": [ - "if (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "IfShouldProcess": { - "prefix": "IfShouldProcess", - "description": "Creates ShouldProcess block", - "body": [ - "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Method": { - "prefix": "method", - "description": "Class method definition snippet", - "body": [ - "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "ModuleManifest": { - "prefix": "manifest", - "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.", - "body": [ - "@{", - "\t# If authoring a script module, the RootModule is the name of your .psm1 file", - "\tRootModule = '${module:MyModule}.psm1'", - "", - "\tAuthor = '${author:Cool Person }'", - "", - "\tCompanyName = '${company:Contoso Inc.}'", - "", - "\tModuleVersion = '${ModuleVersion:0.1}'", - "", - "\t# Use the New-Guid command to generate a GUID, and copy/paste into the next line", - "\tGUID = ''", - "", - "\tCopyright = '2017 ${company:Copyright Holder}'", - "", - "\tDescription = '${Description:What does this module do?}'", - "", - "\t# Minimum PowerShell version supported by this module (optional, recommended)", - "\t# PowerShellVersion = ''", - "", - "\t# Which PowerShell Editions does this module work with? (Core, Desktop)", - "\tCompatiblePSEditions = @('Desktop', 'Core')", - "", - "\t# Which PowerShell functions are exported from your module? (eg. Get-CoolObject)", - "\tFunctionsToExport = @('')", - "", - "\t# Which PowerShell aliases are exported from your module? (eg. gco)", - "\tAliasesToExport = @('')", - "", - "\t# Which PowerShell variables are exported from your module? (eg. Fruits, Vegetables)", - "\tVariablesToExport = @('')", - "", - "\t# PowerShell Gallery: Define your module's metadata", - "\tPrivateData = @{", - "\t\tPSData = @{", - "\t\t\t# What keywords represent your PowerShell module? (eg. cloud, tools, framework, vendor)", - "\t\t\tTags = @('${tag1:cooltag1}', '${tag2:cooltag2}')", - "", - "\t\t\t# What software license is your code being released under? (see https://opensource.org/licenses)", - "\t\t\tLicenseUri = ''", - "", - "\t\t\t# What is the URL to your project's website?", - "\t\t\tProjectUri = ''", - "", - "\t\t\t# What is the URI to a custom icon file for your project? (optional)", - "\t\t\tIconUri = ''", - "", - "\t\t\t# What new features, bug fixes, or deprecated features, are part of this release?", - "\t\t\tReleaseNotes = @'", - "'@", - "\t\t}", - "\t}", - "", - "\t# If your module supports updateable help, what is the URI to the help archive? (optional)", - "\t# HelpInfoURI = ''", - "}" - ] - }, - "Parameter": { - "prefix": "parameter", - "description": "Parameter declaration snippet", - "body": [ - "# ${1:Parameter help description}", - "[Parameter(${2:AttributeValues})]", - "[${3:ParameterType}]", - "$${0:ParameterName}" - ] - }, - "Parameter_Block": { - "prefix": "param-block", - "description": "A Parameter block to get you started.", - "body": [ - "[CmdletBinding()]", - "param (", - " [Parameter()]", - " [${1:TypeName}]", - " $${2:ParameterName}$0", - ")" - ] - }, - "Parameter-LiteralPath": { - "prefix": "parameter-literalpath", - "description": "Parameter declaration snippet for a LiteralPath parameter", - "body": [ - "# Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is", - "# used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters,", - "# enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any", - "# characters as escape sequences.", - "[Parameter(Mandatory=\\$true,", - " Position=${1:0},", - " ParameterSetName=\"${2:LiteralPath}\",", - " ValueFromPipelineByPropertyName=\\$true,", - " HelpMessage=\"Literal path to one or more locations.\")]", - "[Alias(\"PSPath\")]", - "[ValidateNotNullOrEmpty()]", - "[string[]]", - "$${2:LiteralPath}$0" - ] - }, - "Parameter-Path": { - "prefix": "parameter-path", - "description": "Parameter declaration snippet for Path parameter that does not accept wildcards. Do not use with parameter-literalpath.", - "body": [ - "# Specifies a path to one or more locations.", - "[Parameter(Mandatory=\\$true,", - " Position=${1:0},", - " ParameterSetName=\"${2:ParameterSetName}\",", - " ValueFromPipeline=\\$true,", - " ValueFromPipelineByPropertyName=\\$true,", - " HelpMessage=\"Path to one or more locations.\")]", - "[Alias(\"PSPath\")]", - "[ValidateNotNullOrEmpty()]", - "[string[]]", - "$${3:ParameterName}$0" - ] - }, - "Parameter-Path-Wildcards": { - "prefix": "parameter-path-wildcards", - "description": "Parameter declaration snippet for Path parameter that accepts wildcards. Add parameter-literalpath to handle paths with embedded wildcard chars.", - "body": [ - "# Specifies a path to one or more locations. Wildcards are permitted.", - "[Parameter(Mandatory=\\$true,", - " Position=${1:Position},", - " ParameterSetName=\"${2:ParameterSetName}\",", - " ValueFromPipeline=\\$true,", - " ValueFromPipelineByPropertyName=\\$true,", - " HelpMessage=\"Path to one or more locations.\")]", - "[ValidateNotNullOrEmpty()]", - "[SupportsWildcards()]", - "[string[]]", - "$${3:ParameterName}$0" - ] - }, - "PesterContext": { - "prefix": "Context-Pester", - "description": "Pester - Context block", - "body": [ - "Context \"${1:ContextName}\" {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "PesterContextIt": { - "prefix": "Context-It-Pester", - "description": "Pester - Context block with nested It block", - "body": [ - "Context \"${1:ContextName}\" {", - "\tIt \"${2:ItName}\" {", - "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", - "\t}$0", - "}" - ] - }, - "PesterDescribeBlock": { - "prefix": "Describe-Pester", - "description": "Pester Describe block", - "body": [ - "Describe \"${1:DescribeName}\" {", - "\t${0:TM_SELECTED_TEXT}", - "}" - ] - }, - "PesterDescribeContextIt": { - "prefix": "Describe-Context-It-Pester", - "description": "Pester Describe block with nested Context & It blocks", - "body": [ - "Describe \"${1:DescribeName}\" {", - "\tContext \"${2:ContextName}\" {", - "\t\tIt \"${3:ItName}\" {", - "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", - "\t\t}$0", - "\t}", - "}" - ] - }, - "PesterIt": { - "prefix": "It-Pester", - "description": "Pester - It block", - "body": [ - "It \"${1:ItName}\" {", - "\t${2:${TM_SELECTED_TEXT:Assertion}}", - "}$0" - ] - }, - "Property": { - "prefix": "prop", - "description": "Class property definition snippet", - "body": [ - "[${1:string}] $${0:PropertyName}" - ] - }, - "PSCustomObject": { - "prefix": "[PSCustomObject]", - "description": "Creates a PSCustomObject", - "body": [ - "[PSCustomObject]@{", - "\t${1:Name} = ${2:Value}", - "}" - ] - }, - "Region Block": { - "prefix": "#region", - "description": "Region Block for organizing and folding of your code", - "body": [ - "#region ${1}", - "${0:$TM_SELECTED_TEXT}", - "#endregion" - ] - }, - "Requires Assembly": { - "prefix": "requires-assembly", - "description": "Requires an assembly (by name) in order to execute the containing script file.", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'" - }, - "Requires Assembly Path": { - "prefix": "requires-assembly-path", - "description": "Requires an assembly (by relative or absolute path) in order to execute the containing script file.", - "body": "#Requires -Assembly ${0:${TM_SELECTED_TEXT:path/to/assembly.dll}}" - }, - "Requires Assembly Version": { - "prefix": "requires-assembly-version", - "description": "Requires an assembly (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}, Version=${2:1.0.0.0}'" - }, - "Requires Module": { - "prefix": "requires-module", - "description": "Requires a module (by name) in order to execute the containing script file.", - "body": "#Requires -Module ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" - }, - "Requires Module RequiredVersion": { - "prefix": "requires-module-required-version", - "description": "Requires a module (by name and exact version) in order to execute the containing script file.", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; RequiredVersion = '${2:exact-required-version}' }" - }, - "Requires Module Version": { - "prefix": "requires-module-version", - "description": "Requires a module (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; ModuleVersion = '${2:minimum-acceptable-version}' }" - }, - "Requires PSEdition": { - "prefix": "requires-ps-edition", - "description": "Requires a specific edition of PowerShell in order to execute the containing script file.", - "body": "#Requires -PSEdition ${1|Core,Desktop|}" - }, - "Requires PSSnapin": { - "prefix": "requires-ps-snapin", - "description": "Requires a PowerShell snap-in (by name) in order to execute the containing script file.", - "body": "#Requires -PSSnapin ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" - }, - "Requires PSSnapin Version": { - "prefix": "requires-ps-snapin-version", - "description": "Requires a PowerShell snap-in (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -PSSnapin ${1:${TM_SELECTED_TEXT:fully-qualified-name}} -Version ${2:minimum-acceptable-version}" - }, - "Requires RunAsAdministrator": { - "prefix": "requires-run-as-administrator", - "description": "Requires elevated user rights in order to execute the containing script file. Ignored on non-Windows systems. On Windows systems, it requires that the PowerShell session in which the containing script file is run must have been started with elevated user rights (\"Run as Administrator\").", - "body": "#Requires -RunAsAdministrator" - }, - "Requires ShellId": { - "prefix": "requires-shell-id", - "description": "Requires a specific shell id in order to execute the containing script file. The current shell id may be determined by querying the $ShellId automatic variable.", - "body": "#Requires -ShellId ${0:${TM_SELECTED_TEXT:shell-id}}" - }, - "Requires Version": { - "prefix": "requires-version", - "description": "Requires a minimum version of PowerShell in order to execute the containing script file.", - "body": "#Requires -Version ${0:${TM_SELECTED_TEXT:minimum-acceptable-version}}" - }, - "Suppress PSScriptAnalyzer Rule": { - "prefix": "suppress-message-rule", - "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" - ] - }, - "Suppress PSScriptAnalyzer Rule in Scope": { - "prefix": "suppress-message-rule-for-scope", - "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" - ] - }, - "Suppress PSScriptAnalyzer Rule on Parameter": { - "prefix": "suppress-message-rule-for-parameter", - "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" - ] - }, - "switch": { - "prefix": "switch", - "description": "switch statement snippet", - "body": [ - "switch (${1:\\$x}) {", - "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }", - "\tDefault {}", - "}" - ] - }, - "try-catch": { - "prefix": "try", - "description": "try-catch snippet", - "body": [ - "try {", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "catch {", - "\t", - "}" - ] - }, - "try-catch-finally": { - "prefix": "trycf", - "description": "try-catch-finally snippet", - "body": [ - "try {", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "catch {", - "\t", - "}", - "finally {", - "\t", - "}" - ] - }, - "try-finally": { - "prefix": "tryf", - "description": "try-finally snippet", - "body": [ - "try {", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "finally {", - "\t", - "}" - ] - }, - "while": { - "prefix": "while", - "description": "while loop snippet", - "body": [ - "while (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow": { - "prefix": "workflow", - "description": "workflow snippet", - "body": [ - "workflow ${name:Verb-Noun} {", - "\tparam (", - "\t)", - "", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow ForEachParallel": { - "prefix": "workflow foreach-parallel", - "description": "foreach-parallel snippet (for use inside a workflow)", - "body": [ - "foreach -parallel ($${variable:item} in $${collection:collection}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow InlineScript": { - "prefix": "workflow inlinescript", - "description": "inlinescript snippet (for use inside a workflow)", - "body": [ - "inlineScript {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow Parallel": { - "prefix": "workflow parallel", - "description": "parallel snippet (for use inside a workflow)", - "body": [ - "parallel {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow Sequence": { - "prefix": "workflow sequence", - "description": "sequence snippet (for use inside a workflow)", - "body": [ - "sequence {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - } + "ArgumentCompleterAttribute ScriptBlock": { + "prefix": "completer-scriptblock", + "description": "ArgumentCompleter parameter attribute script block definition", + "body": [ + "{", + "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", + "\tparam(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "ArgumentCompleterAttribute with ScriptBlock": { + "prefix": "completer-attribute", + "description": "ArgumentCompleter parameter attribute with script block definition", + "body": [ + "[ArgumentCompleter({", + "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", + "\tparam(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "})]" + ] + }, + "CalculatedProperty": { + "prefix": "Calculated-Property", + "description": "Creates a Calculated Property typically used with Select-Object.", + "body": [ + "@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" + ] + }, + "Class": { + "prefix": "class", + "description": "Class definition snippet", + "body": [ + "class ${1:ClassName} {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "comment block": { + "prefix": "comment", + "description": "Comment block snippet", + "body": [ + "<#", + " # ${0:$TM_SELECTED_TEXT}", + " #>" + ] + }, + "Comment-Help": { + "prefix": "comment-help", + "description": "Comment-based help for an advanced function snippet", + "body": [ + "<#", + ".SYNOPSIS", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tPS C:\\> ", + "\tExplanation of what the example does", + ".INPUTS", + "\tInputs (if any)", + ".OUTPUTS", + "\tOutput (if any)", + ".NOTES", + "\tGeneral notes", + "#>" + ] + }, + "Constructor": { + "prefix": "ctor", + "description": "Class constructor definition snippet", + "body": [ + "${1:ClassName}(${2:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "do-until": { + "prefix": "do-until", + "description": "do-until loop snippet", + "body": [ + "do {", + "\t${0:$TM_SELECTED_TEXT}", + "} until (${1:condition})" + ] + }, + "do-while": { + "prefix": "do-while", + "description": "do-while loop snippet", + "body": [ + "do {", + "\t${0:$TM_SELECTED_TEXT}", + "} while (${1:condition})" + ] + }, + "DSC Ensure Enum": { + "prefix": "DSC Ensure enum", + "description": "DSC Ensure enum definition snippet", + "body": [ + "enum Ensure {", + "\tAbsent", + "\tPresent", + "}" + ] + }, + "DSC Resource Provider (class-based)": { + "prefix": "DSC resource provider (class-based)", + "description": "Class-based DSC resource provider snippet", + "body": [ + "[DscResource()]", + "class ${ResourceName:NameOfResource} {", + "\t[DscProperty(Key)]", + "\t[string] $${PropertyName:KeyName}", + "\t", + "\t# Gets the resource's current state.", + "\t[${ResourceName:NameOfResource}] Get() {", + "\t\t${0:$TM_SELECTED_TEXT}", + "\t\treturn \\$this", + "\t}", + "\t", + "\t# Sets the desired state of the resource.", + "\t[void] Set() {", + "\t\t", + "\t}", + "\t", + "\t# Tests if the resource is in the desired state.", + "\t[bool] Test() {", + "\t\t", + "\t}", + "}" + ] + }, + "DSC Resource Provider (function-based)": { + "prefix": "DSC resource provider (function-based)", + "description": "Function-based DSC resource provider snippet", + "body": [ + "function Get-TargetResource {", + "\tparam (", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "function Set-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}", + "function Test-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}" + ] + }, + "else": { + "prefix": "else", + "description": "else statement snippet", + "body": [ + "else {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "elseif": { + "prefix": "elseif", + "description": "elseif statement snippet", + "body": [ + "elseif (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Enum": { + "prefix": "enum", + "description": "Enum definition snippet", + "body": [ + "enum ${1:EnumName} {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Example-Advanced Workflow": { + "prefix": "ex-advanced workflow", + "description": "Example: advanced workflow snippet", + "body": [ + "<#", + ".Synopsis", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tExample of how to use this workflow", + ".EXAMPLE", + "\tAnother example of how to use this workflow", + ".INPUTS", + "\tInputs to this workflow (if any)", + ".OUTPUTS", + "\tOutput from this workflow (if any)", + ".NOTES", + "\tGeneral notes", + ".FUNCTIONALITY", + "\tThe functionality that best describes this workflow", + "#>", + "workflow ${name:Verb-Noun} {", + "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", + "\t HelpUri = 'http://www.microsoft.com/',", + "\t ConfirmImpact='Medium')]", + "\t[Alias()]", + "\t[OutputType([String])]", + "\tparam (", + "\t\t# Param1 help description", + "\t\t[Parameter(Mandatory=\\$true, ", + "\t\t Position=0,", + "\t\t ParameterSetName='Parameter Set 1')]", + "\t\t[ValidateNotNull()]", + "\t\t[Alias(\"p1\")] ", + "\t\t\\$Param1,", + "", + "\t\t# Param2 help description", + "\t\t[int]", + "\t\t\\$Param2", + "\t)", + "", + "\t# Saves (persists) the current workflow state and output", + "\t# Checkpoint-Workflow", + "\t# Suspends the workflow", + "\t# Suspend-Workflow", + "", + "\t# Workflow common parameters are available as variables such as:", + "\t\\$PSPersist ", + "\t\\$PSComputerName", + "\t\\$PSCredential", + "\t\\$PSUseSsl", + "\t\\$PSAuthentication", + "", + "\t# Workflow runtime information can be accessed by using the following variables:", + "\t\\$Input", + "\t\\$PSSenderInfo", + "\t\\$PSWorkflowRoot", + "\t\\$JobCommandName", + "\t\\$ParentCommandName", + "\t\\$JobId", + "\t\\$ParentJobId", + "\t\\$WorkflowInstanceId", + "\t\\$JobInstanceId", + "\t\\$ParentJobInstanceId", + "\t\\$JobName", + "\t\\$ParentJobName", + "", + "\t# Set the progress message ParentActivityId", + "\t\\$PSParentActivityId", + "", + "\t# Preference variables that control runtime behavior", + "\t\\$PSRunInProcessPreference", + "\t\\$PSPersistPreference", + "}" + ] + }, + "Example-Class": { + "prefix": "ex-class", + "description": "Example: class snippet with a constructor, property and a method", + "body": [ + "class ${1:MyClass} {", + "\t# Property: Holds name", + "\t[String] \\$Name", + "", + "\t# Constructor: Creates a new MyClass object, with the specified name", + "\t${1:MyClass}([String] \\$NewName) {", + "\t\t# Set name for ${1:MyClass}", + "\t\t\\$this.Name = \\$NewName", + "\t}", + "", + "\t# Method: Method that changes \\$Name to the default name", + "\t[void] ChangeNameToDefault() {", + "\t\t\\$this.Name = \"DefaultName\"", + "\t}", + "}" + ] + }, + "Example-Cmdlet": { + "prefix": "ex-cmdlet", + "description": "Example: script cmdlet snippet with all attributes and inline help fields", + "body": [ + "<#", + ".SYNOPSIS", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tExample of how to use this cmdlet", + ".EXAMPLE", + "\tAnother example of how to use this cmdlet", + ".INPUTS", + "\tInputs to this cmdlet (if any)", + ".OUTPUTS", + "\tOutput from this cmdlet (if any)", + ".NOTES", + "\tGeneral notes", + ".COMPONENT", + "\tThe component this cmdlet belongs to", + ".ROLE", + "\tThe role this cmdlet belongs to", + ".FUNCTIONALITY", + "\tThe functionality that best describes this cmdlet", + "#>", + "function ${name:Verb-Noun} {", + "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", + "\t SupportsShouldProcess=\\$true,", + "\t PositionalBinding=\\$false,", + "\t HelpUri = 'http://www.microsoft.com/',", + "\t ConfirmImpact='Medium')]", + "\t[Alias()]", + "\t[OutputType([String])]", + "\tParam (", + "\t\t# Param1 help description", + "\t\t[Parameter(Mandatory=\\$true,", + "\t\t Position=0,", + "\t\t ValueFromPipeline=\\$true,", + "\t\t ValueFromPipelineByPropertyName=\\$true,", + "\t\t ValueFromRemainingArguments=\\$false, ", + "\t\t ParameterSetName='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", + "\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", + "\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", + "\tbegin {", + "\t}", + "\t", + "\tprocess {", + "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", + "\t\t\t$0", + "\t\t}", + "\t}", + "\t", + "\tend {", + "\t}", + "}" + ] + }, + "Example-DSC Configuration": { + "prefix": "ex-DSC config", + "description": "Example: DSC configuration snippet that uses built-in resource providers", + "body": [ + "configuration Name {", + "\t# One can evaluate expressions to get the node list", + "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", + "\tnode (\"Node1\",\"Node2\",\"Node3\")", + "\t{", + "\t\t# Call Resource Provider", + "\t\t# E.g: WindowsFeature, File", + "\t\tWindowsFeature FriendlyName", + "\t\t{", + "\t\t\tEnsure = \"Present\"", + "\t\t\tName = \"Feature Name\"", + "\t\t}", + "", + "\t\tFile FriendlyName", + "\t\t{", + "\t\t\tEnsure = \"Present\"", + "\t\t\tSourcePath = \\$SourcePath", + "\t\t\tDestinationPath = \\$DestinationPath", + "\t\t\tType = \"Directory\"", + "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", + "\t\t}", + "\t}", + "}" + ] + }, + "Example-DSC Resource Provider (class-based)": { + "prefix": "ex-DSC resource provider (class-based)", + "description": "Example: class-based DSC resource provider snippet", + "body": [ + "# Defines the values for the resource's Ensure property.", + "enum Ensure {", + "\t# The resource must be absent.", + "\tAbsent", + "\t# The resource must be present.", + "\tPresent", + "}", + "", + "# [DscResource()] indicates the class is a DSC resource.", + "[DscResource()]", + "class NameOfResource {", + "\t# A DSC resource must define at least one key property.", + "\t[DscProperty(Key)]", + "\t[string] \\$P1", + "\t", + "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", + "\t[DscProperty(Mandatory)]", + "\t[Ensure] \\$P2", + "\t", + "\t# NotConfigurable properties return additional information about the state of the resource.", + "\t# For example, a Get() method might return the date a resource was last modified.", + "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", + "\t[DscProperty(NotConfigurable)]", + "\t[Nullable[datetime]] \\$P3", + "\t", + "\t[DscProperty()]", + "\t[ValidateSet(\"val1\", \"val2\")]", + "\t[string] \\$P4", + "\t", + "\t# Gets the resource's current state.", + "\t[NameOfResource] Get() {", + "\t\t# NotConfigurable properties are set in the Get method.", + "\t\t\\$this.P3 = something", + "\t\t# Return this instance or construct a new instance.", + "\t\treturn \\$this", + "\t}", + "\t", + "\t# Sets the desired state of the resource.", + "\t[void] Set() {", + "\t}", + "\t", + "\t# Tests if the resource is in the desired state.", + "\t[bool] Test() {", + "\t\t return \\$true", + "\t}", + "}" + ] + }, + "Example-DSC Resource Provider (function based)": { + "prefix": "ex-DSC resource provider (function based)", + "description": "Example: function-based DSC resource provider snippet", + "body": [ + "function Get-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}", + "function Set-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}", + "function Test-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}" + ] + }, + "Example-Path Processing for No Wildcards Allowed": { + "prefix": "ex-path processing for no wildcards allowed", + "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + "\\$paths = @()", + "foreach (\\$aPath in \\$Path) {", + "\tif (!(Test-Path -LiteralPath \\$aPath)) {", + "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\tcontinue", + "\t}", + "", + "\t# Resolve any relative paths", + "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Path Processing for Non-Existing Paths": { + "prefix": "ex-path processing for non-existing paths", + "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + "\\$paths = @()", + "foreach (\\$aPath in \\$Path) {", + "\t# Resolve any relative paths", + "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Path Processing for Wildcards Allowed": { + "prefix": "ex-path processing for wildcards allowed", + "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", + "\\$paths = @()", + "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", + "\tforeach (\\$aPath in \\$Path) {", + "\t\tif (!(Test-Path -Path \\$aPath)) {", + "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\t\tcontinue", + "\t\t}", + "\t", + "\t\t# Resolve any wildcards that might be in the path", + "\t\t\\$provider = \\$null", + "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", + "\t}", + "}", + "else {", + "\tforeach (\\$aPath in \\$LiteralPath) {", + "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", + "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\t\tcontinue", + "\t\t}", + "\t", + "\t\t# Resolve any relative paths", + "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "\t}", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Splatting": { + "prefix": "ex-splat", + "description": "Example: PowerShell splatting technique snippet", + "body": [ + "\\$Params = @{", + "\tModule = '*'", + "\tVerb = 'Get'", + "}", + "Get-Command @Params" + ] + }, + "Example-Switch": { + "prefix": "ex-switch", + "description": "Example: switch statement snippet", + "body": [ + "switch (${variable:\\$x})", + "{", + "\t'${val:value1}' { $1 }", + "\t{\\$_ -in 'A','B','C'} {}", + "\t'value3' {}", + "\tDefault {}", + "}" + ] + }, + "for": { + "prefix": "for", + "description": "for loop snippet", + "body": [ + "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "for-reversed": { + "prefix": "forr", + "description": "reversed for loop snippet", + "body": [ + "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "foreach": { + "prefix": "foreach", + "description": "foreach loop snippet", + "body": [ + "foreach ($${1:item} in $${2:collection}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "function": { + "prefix": "function", + "description": "Function definition snippet that contains a param block", + "body": [ + "function ${1:FunctionName} {", + "\tparam (", + "\t\t${2:OptionalParameters}", + "\t)", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Function-Advanced": { + "prefix": [ + "function-advanced", + "cmdlet" + ], + "description": "Script advanced function definition snippet", + "body": [ + "function ${1:Verb-Noun} {", + "\t[CmdletBinding()]", + "\tparam (", + "\t\t$0", + "\t)", + "\t", + "\tbegin {", + "\t\t", + "\t}", + "\t", + "\tprocess {", + "\t\t$TM_SELECTED_TEXT", + "\t}", + "\t", + "\tend {", + "\t\t", + "\t}", + "}" + ] + }, + "Function-Help": { + "prefix": "help-function", + "description": "Comment-based help for an advanced function snippet", + "body": [ + "<#", + ".SYNOPSIS", + "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", + ".DESCRIPTION", + "\t${2:A longer description of the function, its purpose, common use cases, etc.}", + ".NOTES", + "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", + ".LINK", + "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", + ".EXAMPLE", + "\t${5:Test-MyTestFunction -Verbose}", + "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", + "#>" + ] + }, + "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", + "body": [ + "function ${1:FunctionName} (${2:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Hashtable": { + "prefix": "Hashtable", + "description": "Creates a Hashtable", + "body": [ + "\\$${1:Var} = @{", + "\t${2:Name} = ${3:Value}", + "}" + ] + }, + "Hidden Property": { + "prefix": "proph", + "description": "Class hidden property definition snippet", + "body": [ + "hidden [${1:string}] $${0:PropertyName}" + ] + }, + "IArgumentCompleter Class": { + "prefix": "completer-class", + "description": "IArgumentCompleter implementation class definition", + "body": [ + "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", + "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", + "\t\t[string] \\$CommandName,", + "\t\t[string] \\$ParameterName,", + "\t\t[string] \\$WordToComplete,", + "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", + "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", + "\t) {", + "\t\t\\$CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()", + "\t\t", + "\t\t${0:$TM_SELECTED_TEXT}", + "\t\t", + "\t\treturn \\$CompletionResults", + "\t}", + "}" + ] + }, + "if": { + "prefix": "if", + "description": "if statement snippet", + "body": [ + "if (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "IfShouldProcess": { + "prefix": "IfShouldProcess", + "description": "Creates ShouldProcess block", + "body": [ + "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Method": { + "prefix": "method", + "description": "Class method definition snippet", + "body": [ + "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "ModuleManifest": { + "prefix": "manifest", + "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.", + "body": [ + "@{", + "\t# If authoring a script module, the RootModule is the name of your .psm1 file", + "\tRootModule = '${module:MyModule}.psm1'", + "", + "\tAuthor = '${author:Cool Person }'", + "", + "\tCompanyName = '${company:Contoso Inc.}'", + "", + "\tModuleVersion = '${ModuleVersion:0.1}'", + "", + "\t# Use the New-Guid command to generate a GUID, and copy/paste into the next line", + "\tGUID = ''", + "", + "\tCopyright = '2017 ${company:Copyright Holder}'", + "", + "\tDescription = '${Description:What does this module do?}'", + "", + "\t# Minimum PowerShell version supported by this module (optional, recommended)", + "\t# PowerShellVersion = ''", + "", + "\t# Which PowerShell Editions does this module work with? (Core, Desktop)", + "\tCompatiblePSEditions = @('Desktop', 'Core')", + "", + "\t# Which PowerShell functions are exported from your module? (eg. Get-CoolObject)", + "\tFunctionsToExport = @('')", + "", + "\t# Which PowerShell aliases are exported from your module? (eg. gco)", + "\tAliasesToExport = @('')", + "", + "\t# Which PowerShell variables are exported from your module? (eg. Fruits, Vegetables)", + "\tVariablesToExport = @('')", + "", + "\t# PowerShell Gallery: Define your module's metadata", + "\tPrivateData = @{", + "\t\tPSData = @{", + "\t\t\t# What keywords represent your PowerShell module? (eg. cloud, tools, framework, vendor)", + "\t\t\tTags = @('${tag1:cooltag1}', '${tag2:cooltag2}')", + "", + "\t\t\t# What software license is your code being released under? (see https://opensource.org/licenses)", + "\t\t\tLicenseUri = ''", + "", + "\t\t\t# What is the URL to your project's website?", + "\t\t\tProjectUri = ''", + "", + "\t\t\t# What is the URI to a custom icon file for your project? (optional)", + "\t\t\tIconUri = ''", + "", + "\t\t\t# What new features, bug fixes, or deprecated features, are part of this release?", + "\t\t\tReleaseNotes = @'", + "'@", + "\t\t}", + "\t}", + "", + "\t# If your module supports updateable help, what is the URI to the help archive? (optional)", + "\t# HelpInfoURI = ''", + "}" + ] + }, + "Parameter": { + "prefix": "parameter", + "description": "Parameter declaration snippet", + "body": [ + "# ${1:Parameter help description}", + "[Parameter(${2:AttributeValues})]", + "[${3:ParameterType}]", + "$${0:ParameterName}" + ] + }, + "Parameter_Block": { + "prefix": "param-block", + "description": "A Parameter block to get you started.", + "body": [ + "[CmdletBinding()]", + "param (", + " [Parameter()]", + " [${1:TypeName}]", + " $${2:ParameterName}$0", + ")" + ] + }, + "Parameter-LiteralPath": { + "prefix": "parameter-literalpath", + "description": "Parameter declaration snippet for a LiteralPath parameter", + "body": [ + "# Specifies a path to one or more locations. Unlike the Path parameter, the value of the LiteralPath parameter is", + "# used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters,", + "# enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any", + "# characters as escape sequences.", + "[Parameter(Mandatory=\\$true,", + " Position=${1:0},", + " ParameterSetName=\"${2:LiteralPath}\",", + " ValueFromPipelineByPropertyName=\\$true,", + " HelpMessage=\"Literal path to one or more locations.\")]", + "[Alias(\"PSPath\")]", + "[ValidateNotNullOrEmpty()]", + "[string[]]", + "$${2:LiteralPath}$0" + ] + }, + "Parameter-Path": { + "prefix": "parameter-path", + "description": "Parameter declaration snippet for Path parameter that does not accept wildcards. Do not use with parameter-literalpath.", + "body": [ + "# Specifies a path to one or more locations.", + "[Parameter(Mandatory=\\$true,", + " Position=${1:0},", + " ParameterSetName=\"${2:ParameterSetName}\",", + " ValueFromPipeline=\\$true,", + " ValueFromPipelineByPropertyName=\\$true,", + " HelpMessage=\"Path to one or more locations.\")]", + "[Alias(\"PSPath\")]", + "[ValidateNotNullOrEmpty()]", + "[string[]]", + "$${3:ParameterName}$0" + ] + }, + "Parameter-Path-Wildcards": { + "prefix": "parameter-path-wildcards", + "description": "Parameter declaration snippet for Path parameter that accepts wildcards. Add parameter-literalpath to handle paths with embedded wildcard chars.", + "body": [ + "# Specifies a path to one or more locations. Wildcards are permitted.", + "[Parameter(Mandatory=\\$true,", + " Position=${1:Position},", + " ParameterSetName=\"${2:ParameterSetName}\",", + " ValueFromPipeline=\\$true,", + " ValueFromPipelineByPropertyName=\\$true,", + " HelpMessage=\"Path to one or more locations.\")]", + "[ValidateNotNullOrEmpty()]", + "[SupportsWildcards()]", + "[string[]]", + "$${3:ParameterName}$0" + ] + }, + "PesterContext": { + "prefix": "Context-Pester", + "description": "Pester - Context block", + "body": [ + "Context \"${1:ContextName}\" {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "PesterContextIt": { + "prefix": "Context-It-Pester", + "description": "Pester - Context block with nested It block", + "body": [ + "Context \"${1:ContextName}\" {", + "\tIt \"${2:ItName}\" {", + "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", + "\t}$0", + "}" + ] + }, + "PesterDescribeBlock": { + "prefix": "Describe-Pester", + "description": "Pester Describe block", + "body": [ + "Describe \"${1:DescribeName}\" {", + "\t${0:TM_SELECTED_TEXT}", + "}" + ] + }, + "PesterDescribeContextIt": { + "prefix": "Describe-Context-It-Pester", + "description": "Pester Describe block with nested Context & It blocks", + "body": [ + "Describe \"${1:DescribeName}\" {", + "\tContext \"${2:ContextName}\" {", + "\t\tIt \"${3:ItName}\" {", + "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", + "\t\t}$0", + "\t}", + "}" + ] + }, + "PesterIt": { + "prefix": "It-Pester", + "description": "Pester - It block", + "body": [ + "It \"${1:ItName}\" {", + "\t${2:${TM_SELECTED_TEXT:Assertion}}", + "}$0" + ] + }, + "Property": { + "prefix": "prop", + "description": "Class property definition snippet", + "body": [ + "[${1:string}] $${0:PropertyName}" + ] + }, + "PSCustomObject": { + "prefix": "[PSCustomObject]", + "description": "Creates a PSCustomObject", + "body": [ + "[PSCustomObject]@{", + "\t${1:Name} = ${2:Value}", + "}" + ] + }, + "Region Block": { + "prefix": "#region", + "description": "Region Block for organizing and folding of your code", + "body": [ + "#region ${1}", + "${0:$TM_SELECTED_TEXT}", + "#endregion" + ] + }, + "Requires Assembly": { + "prefix": "requires-assembly", + "description": "Requires an assembly (by name) in order to execute the containing script file.", + "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'" + }, + "Requires Assembly Path": { + "prefix": "requires-assembly-path", + "description": "Requires an assembly (by relative or absolute path) in order to execute the containing script file.", + "body": "#Requires -Assembly ${0:${TM_SELECTED_TEXT:path/to/assembly.dll}}" + }, + "Requires Assembly Version": { + "prefix": "requires-assembly-version", + "description": "Requires an assembly (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}, Version=${2:1.0.0.0}'" + }, + "Requires Module": { + "prefix": "requires-module", + "description": "Requires a module (by name) in order to execute the containing script file.", + "body": "#Requires -Module ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" + }, + "Requires Module RequiredVersion": { + "prefix": "requires-module-required-version", + "description": "Requires a module (by name and exact version) in order to execute the containing script file.", + "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; RequiredVersion = '${2:exact-required-version}' }" + }, + "Requires Module Version": { + "prefix": "requires-module-version", + "description": "Requires a module (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; ModuleVersion = '${2:minimum-acceptable-version}' }" + }, + "Requires PSEdition": { + "prefix": "requires-ps-edition", + "description": "Requires a specific edition of PowerShell in order to execute the containing script file.", + "body": "#Requires -PSEdition ${1|Core,Desktop|}" + }, + "Requires PSSnapin": { + "prefix": "requires-ps-snapin", + "description": "Requires a PowerShell snap-in (by name) in order to execute the containing script file.", + "body": "#Requires -PSSnapin ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" + }, + "Requires PSSnapin Version": { + "prefix": "requires-ps-snapin-version", + "description": "Requires a PowerShell snap-in (by name and minimum version) in order to execute the containing script file.", + "body": "#Requires -PSSnapin ${1:${TM_SELECTED_TEXT:fully-qualified-name}} -Version ${2:minimum-acceptable-version}" + }, + "Requires RunAsAdministrator": { + "prefix": "requires-run-as-administrator", + "description": "Requires elevated user rights in order to execute the containing script file. Ignored on non-Windows systems. On Windows systems, it requires that the PowerShell session in which the containing script file is run must have been started with elevated user rights (\"Run as Administrator\").", + "body": "#Requires -RunAsAdministrator" + }, + "Requires ShellId": { + "prefix": "requires-shell-id", + "description": "Requires a specific shell id in order to execute the containing script file. The current shell id may be determined by querying the $ShellId automatic variable.", + "body": "#Requires -ShellId ${0:${TM_SELECTED_TEXT:shell-id}}" + }, + "Requires Version": { + "prefix": "requires-version", + "description": "Requires a minimum version of PowerShell in order to execute the containing script file.", + "body": "#Requires -Version ${0:${TM_SELECTED_TEXT:minimum-acceptable-version}}" + }, + "Suppress PSScriptAnalyzer Rule": { + "prefix": "suppress-message-rule", + "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" + ] + }, + "Suppress PSScriptAnalyzer Rule in Scope": { + "prefix": "suppress-message-rule-for-scope", + "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" + ] + }, + "Suppress PSScriptAnalyzer Rule on Parameter": { + "prefix": "suppress-message-rule-for-parameter", + "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" + ] + }, + "switch": { + "prefix": "switch", + "description": "switch statement snippet", + "body": [ + "switch (${1:\\$x}) {", + "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }", + "\tDefault {}", + "}" + ] + }, + "try-catch": { + "prefix": "try", + "description": "try-catch snippet", + "body": [ + "try {", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "catch {", + "\t", + "}" + ] + }, + "try-catch-finally": { + "prefix": "trycf", + "description": "try-catch-finally snippet", + "body": [ + "try {", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "catch {", + "\t", + "}", + "finally {", + "\t", + "}" + ] + }, + "try-finally": { + "prefix": "tryf", + "description": "try-finally snippet", + "body": [ + "try {", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "finally {", + "\t", + "}" + ] + }, + "while": { + "prefix": "while", + "description": "while loop snippet", + "body": [ + "while (${1:condition}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Workflow": { + "prefix": "workflow", + "description": "workflow snippet", + "body": [ + "workflow ${name:Verb-Noun} {", + "\tparam (", + "\t)", + "", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Workflow ForEachParallel": { + "prefix": "workflow foreach-parallel", + "description": "foreach-parallel snippet (for use inside a workflow)", + "body": [ + "foreach -parallel ($${variable:item} in $${collection:collection}) {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Workflow InlineScript": { + "prefix": "workflow inlinescript", + "description": "inlinescript snippet (for use inside a workflow)", + "body": [ + "inlineScript {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Workflow Parallel": { + "prefix": "workflow parallel", + "description": "parallel snippet (for use inside a workflow)", + "body": [ + "parallel {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "Workflow Sequence": { + "prefix": "workflow sequence", + "description": "sequence snippet (for use inside a workflow)", + "body": [ + "sequence {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + } } From 46a6ba0c2d759b5403e0289faa9d64a6fedb551b Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 10:14:00 -0800 Subject: [PATCH 04/14] ArgumentCompleterAttribute --- snippets/PowerShell.json | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 42a5dccc8f..7c7e2cb0b3 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,29 +1,11 @@ // The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { - "ArgumentCompleterAttribute ScriptBlock": { - "prefix": "completer-scriptblock", - "description": "ArgumentCompleter parameter attribute script block definition", - "body": [ - "{", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", - "\tparam(", - "\t\t[string] \\$CommandName,", - "\t\t[string] \\$ParameterName,", - "\t\t[string] \\$WordToComplete,", - "\t\t[System.Management.Automation.Language.CommandAst] \\$CommandAst,", - "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "ArgumentCompleterAttribute with ScriptBlock": { - "prefix": "completer-attribute", - "description": "ArgumentCompleter parameter attribute with script block definition", + "ArgumentCompleterAttribute": { + "prefix": "argumentcompleter", + "description": "The ArgumentCompleter attribute allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help -Online about_functions_argument_completion", "body": [ "[ArgumentCompleter({", - "\t[OutputType([System.Management.Automation.CompletionResult])] # zero to many", + "\t[OutputType([System.Management.Automation.CompletionResult])]", "\tparam(", "\t\t[string] \\$CommandName,", "\t\t[string] \\$ParameterName,", @@ -32,8 +14,9 @@ "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", "\t)", "\t", - "\t${0:$TM_SELECTED_TEXT}", - "})]" + "\t${1:$TM_SELECTED_TEXT}", + "\t#Output one or more of these objects: [Management.Automation.CompletionResult]'MyPotentialResult'", + "})]${0}" ] }, "CalculatedProperty": { @@ -625,7 +608,7 @@ }, "function": { "prefix": "function", - "description": "Function definition snippet that contains a param block", + "description": "A simple function with a parameter block to specify function arguments", "body": [ "function ${1:FunctionName} {", "\tparam (", From 114460d75f044de3285bea785de63a5769ba861a Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 10:48:21 -0800 Subject: [PATCH 05/14] ArgumentCompleterAttribute Updates --- snippets/PowerShell.json | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 7c7e2cb0b3..9e6f9d03d0 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,8 +1,11 @@ // The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { "ArgumentCompleterAttribute": { - "prefix": "argumentcompleter", - "description": "The ArgumentCompleter attribute allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help -Online about_functions_argument_completion", + "prefix": [ + "argumentcompleter", + "[ArgumentCompleter(" + ], + "description": "ArgumentCompleter attribute allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help about_Functions_Argument_Completion", "body": [ "[ArgumentCompleter({", "\t[OutputType([System.Management.Automation.CompletionResult])]", @@ -15,15 +18,17 @@ "\t)", "\t", "\t${1:$TM_SELECTED_TEXT}", - "\t#Output one or more of these objects: [Management.Automation.CompletionResult]'MyPotentialResult'", "})]${0}" ] }, "CalculatedProperty": { - "prefix": "Calculated-Property", - "description": "Creates a Calculated Property typically used with Select-Object.", + "prefix": [ + "calculated-property", + "@{Name" + ], + "description": "Calculated Property typically used with Select-Object or Sort-Object. More: Get-Help about_Calculated_Properties", "body": [ - "@{name='${1:PropertyName}';expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" + "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" ] }, "Class": { From 5c69b38df75dc8bf657d3445d6da33980042e94d Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 10:48:34 -0800 Subject: [PATCH 06/14] Add class Help --- snippets/PowerShell.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 9e6f9d03d0..350c4e1907 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -33,7 +33,7 @@ }, "Class": { "prefix": "class", - "description": "Class definition snippet", + "description": "A class declaration is a blueprint used to create instances of objects at run time. More: Get-Help about_Classes", "body": [ "class ${1:ClassName} {", "\t${0:$TM_SELECTED_TEXT}", From c0f82b80c84bceaf785109106038d064a7e57547 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 10:48:54 -0800 Subject: [PATCH 07/14] Remove Comment Help --- snippets/PowerShell.json | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 350c4e1907..576569f098 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -49,27 +49,6 @@ " #>" ] }, - "Comment-Help": { - "prefix": "comment-help", - "description": "Comment-based help for an advanced function snippet", - "body": [ - "<#", - ".SYNOPSIS", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tPS C:\\> ", - "\tExplanation of what the example does", - ".INPUTS", - "\tInputs (if any)", - ".OUTPUTS", - "\tOutput (if any)", - ".NOTES", - "\tGeneral notes", - "#>" - ] - }, "Constructor": { "prefix": "ctor", "description": "Class constructor definition snippet", From 0b49beca92dec406cb0280d88fcca75e1a7e9459 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sat, 19 Feb 2022 18:39:29 -0800 Subject: [PATCH 08/14] Lots of Updates --- snippets/PowerShell.json | 506 +++++++++++++++++---------------------- 1 file changed, 225 insertions(+), 281 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 576569f098..1ac2f997d6 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,11 +1,8 @@ // The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { "ArgumentCompleterAttribute": { - "prefix": [ - "argumentcompleter", - "[ArgumentCompleter(" - ], - "description": "ArgumentCompleter attribute allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help about_Functions_Argument_Completion", + "prefix": "argument-completer", + "description": "Allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help about_Functions_Argument_Completion", "body": [ "[ArgumentCompleter({", "\t[OutputType([System.Management.Automation.CompletionResult])]", @@ -17,63 +14,73 @@ "\t\t[System.Collections.IDictionary] \\$FakeBoundParameters", "\t)", "\t", - "\t${1:$TM_SELECTED_TEXT}", - "})]${0}" + "\t\\$CompletionResults = [System.Collections.Generic.List[System.Management.Automation.CompletionResult]]::new()", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "\t", + "\treturn \\$CompletionResults", + "})]" ] }, - "CalculatedProperty": { - "prefix": [ - "calculated-property", - "@{Name" - ], - "description": "Calculated Property typically used with Select-Object or Sort-Object. More: Get-Help about_Calculated_Properties", + "Calculated Property": { + "prefix": "calculated-property", + "description": "Typically used with Select-Object or Sort-Object. More: Get-Help about_Calculated_Properties", "body": [ "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" ] }, "Class": { "prefix": "class", - "description": "A class declaration is a blueprint used to create instances of objects at run time. More: Get-Help about_Classes", + "description": "A blueprint used to create instances of objects at run time. More: Get-Help about_Classes", "body": [ "class ${1:ClassName} {", - "\t${0:$TM_SELECTED_TEXT}", + "\t${0:${TM_SELECTED_TEXT:#Define the class. Try constructors, properties, or methods}}", "}" ] }, - "comment block": { - "prefix": "comment", - "description": "Comment block snippet", + "Class Constructor": { + "prefix": [ + "ctor-class", + "class-constructor" + ], + "description": "Set default values and validate object logic at the moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have arguments, to initialize the data members of the new object. More: Get-Help about_Classes", "body": [ - "<#", - " # ${0:$TM_SELECTED_TEXT}", - " #>" + "${1:ClassName}(${2:OptionalParameters}) {", + "\t${0:${TM_SELECTED_TEXT:#Initialize the class. Use \\$this to reference the properties of the instance you are creating}}", + "}" ] }, - "Constructor": { - "prefix": "ctor", - "description": "Class constructor definition snippet", + "Comment Block": { + "prefix": [ + "block-comment" + ], + "description": "A multi-line comment.", "body": [ - "${1:ClassName}(${2:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" + "$BLOCK_COMMENT_START", + " # ${{0:$TM_SELECTED_TEXT:Enter a comment or description}}", + "$BLOCK_COMMENT_END" ] }, "do-until": { "prefix": "do-until", - "description": "do-until loop snippet", + "description": "Runs a statement list repeatedly until a condition is met More: Get-Help about_Do", "body": [ "do {", "\t${0:$TM_SELECTED_TEXT}", - "} until (${1:condition})" + "} until (", + "\t${1:#Condition that stops the loop if it returns true}", + ")" ] }, "do-while": { "prefix": "do-while", - "description": "do-while loop snippet", + "description": "Runs a statement list repeatedly as long as a condition is met. More: Get-Help about_Do", "body": [ "do {", "\t${0:$TM_SELECTED_TEXT}", - "} while (${1:condition})" + "} while (", + "\t${1:#Condition that stops the loop if it returns false})", + ")" ] }, "DSC Ensure Enum": { @@ -83,7 +90,8 @@ "enum Ensure {", "\tAbsent", "\tPresent", - "}" + "}", + "$0" ] }, "DSC Resource Provider (class-based)": { @@ -137,7 +145,7 @@ }, "else": { "prefix": "else", - "description": "else statement snippet", + "description": "else defines what is done when all if and elseif conditions are false. More: Get-Help about_If", "body": [ "else {", "\t${0:$TM_SELECTED_TEXT}", @@ -146,7 +154,7 @@ }, "elseif": { "prefix": "elseif", - "description": "elseif statement snippet", + "description": "elseif provides an alternative path when an if condition is false. More: Get-Help about_If", "body": [ "elseif (${1:condition}) {", "\t${0:$TM_SELECTED_TEXT}", @@ -155,90 +163,13 @@ }, "Enum": { "prefix": "enum", - "description": "Enum definition snippet", + "description": "An enumeration is a distinct type that consists of a set of named labels called the enumerator list. More: Get-Help about_Enum", "body": [ "enum ${1:EnumName} {", "\t${0:$TM_SELECTED_TEXT}", "}" ] }, - "Example-Advanced Workflow": { - "prefix": "ex-advanced workflow", - "description": "Example: advanced workflow snippet", - "body": [ - "<#", - ".Synopsis", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tExample of how to use this workflow", - ".EXAMPLE", - "\tAnother example of how to use this workflow", - ".INPUTS", - "\tInputs to this workflow (if any)", - ".OUTPUTS", - "\tOutput from this workflow (if any)", - ".NOTES", - "\tGeneral notes", - ".FUNCTIONALITY", - "\tThe functionality that best describes this workflow", - "#>", - "workflow ${name:Verb-Noun} {", - "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - "\t HelpUri = 'http://www.microsoft.com/',", - "\t ConfirmImpact='Medium')]", - "\t[Alias()]", - "\t[OutputType([String])]", - "\tparam (", - "\t\t# Param1 help description", - "\t\t[Parameter(Mandatory=\\$true, ", - "\t\t Position=0,", - "\t\t ParameterSetName='Parameter Set 1')]", - "\t\t[ValidateNotNull()]", - "\t\t[Alias(\"p1\")] ", - "\t\t\\$Param1,", - "", - "\t\t# Param2 help description", - "\t\t[int]", - "\t\t\\$Param2", - "\t)", - "", - "\t# Saves (persists) the current workflow state and output", - "\t# Checkpoint-Workflow", - "\t# Suspends the workflow", - "\t# Suspend-Workflow", - "", - "\t# Workflow common parameters are available as variables such as:", - "\t\\$PSPersist ", - "\t\\$PSComputerName", - "\t\\$PSCredential", - "\t\\$PSUseSsl", - "\t\\$PSAuthentication", - "", - "\t# Workflow runtime information can be accessed by using the following variables:", - "\t\\$Input", - "\t\\$PSSenderInfo", - "\t\\$PSWorkflowRoot", - "\t\\$JobCommandName", - "\t\\$ParentCommandName", - "\t\\$JobId", - "\t\\$ParentJobId", - "\t\\$WorkflowInstanceId", - "\t\\$JobInstanceId", - "\t\\$ParentJobInstanceId", - "\t\\$JobName", - "\t\\$ParentJobName", - "", - "\t# Set the progress message ParentActivityId", - "\t\\$PSParentActivityId", - "", - "\t# Preference variables that control runtime behavior", - "\t\\$PSRunInProcessPreference", - "\t\\$PSPersistPreference", - "}" - ] - }, "Example-Class": { "prefix": "ex-class", "description": "Example: class snippet with a constructor, property and a method", @@ -590,6 +521,15 @@ "}" ] }, + "ForEach-Object -Parallel": { + "prefix": "foreach-parallel", + "description": "[PS 7+] Process multiple objects in parallel using runspaces. This has some limitations compared to a regular ForEach-Object. More: Get-Help ForEach-Object", + "body": [ + "${1:\\$collection} | Foreach-Object -ThrottleLimit ${2:5} -Parallel {", + " ${0:${TM_SELECTED_TEXT:#Reference items via \\$PSItem and bring in outside variables with \\$USING:varname}}", + "}" + ] + }, "function": { "prefix": "function", "description": "A simple function with a parameter block to specify function arguments", @@ -602,6 +542,30 @@ "}" ] }, + "Function Help": { + "prefix": [ + "help-function", + "comment-help" + ], + "description": "Comment-based help for an advanced function. More: Get-Help about_Comment_Based_Help", + "body": [ + "<#", + ".SYNOPSIS", + "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", + ".DESCRIPTION", + "\t${2:A longer description of the function, its purpose, common use cases, etc.}", + ".NOTES", + "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", + ".LINK", + "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", + ".EXAMPLE", + "\t${5:Test-MyTestFunction -Verbose}", + "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", + "#>", + "", + "{0}" + ] + }, "Function-Advanced": { "prefix": [ "function-advanced", @@ -658,8 +622,11 @@ ] }, "Hashtable": { - "prefix": "Hashtable", - "description": "Creates a Hashtable", + "prefix": [ + "Hashtable", + "@{" + ], + "description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables", "body": [ "\\$${1:Var} = @{", "\t${2:Name} = ${3:Value}", @@ -667,15 +634,15 @@ ] }, "Hidden Property": { - "prefix": "proph", - "description": "Class hidden property definition snippet", + "prefix": "class-proph", + "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: about_Hidden", "body": [ "hidden [${1:string}] $${0:PropertyName}" ] }, "IArgumentCompleter Class": { - "prefix": "completer-class", - "description": "IArgumentCompleter implementation class definition", + "prefix": "iargument-completer", + "description": "Implementation of the IArgumentCompleter interface that can be directly attached to parameters (e.g. [MyCustomArgumentCompleter])", "body": [ "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", @@ -704,7 +671,7 @@ ] }, "IfShouldProcess": { - "prefix": "IfShouldProcess", + "prefix": "if-Should-Process", "description": "Creates ShouldProcess block", "body": [ "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", @@ -783,9 +750,33 @@ "}" ] }, + "Parallel Pipeline Function": { + "prefix": "function-parallel-pipeline", + "description": "Collects everything in the process block and does work in the end block. Useful when making a 'fan out' function that acts on multiple items simultaneously because the pipeline only does one item at a time in the process block.", + "body": [ + "function $1 {", + " [CmdletBinding()]", + " param(", + " [parameter(ValueFromPipeline)]$$2", + " )", + "", + " begin {", + " [Collections.ArrayList]\\$inputObjects = @()", + " }", + " process {", + " [void]\\$inputObjects.Add($$2)", + " }", + " end {", + " \\$inputObjects | Foreach -Parallel {", + " $0", + " }", + " }", + "}" + ] + }, "Parameter": { "prefix": "parameter", - "description": "Parameter declaration snippet", + "description": "A parameter definition for a method or function. More: Get-Help about_Functions", "body": [ "# ${1:Parameter help description}", "[Parameter(${2:AttributeValues})]", @@ -794,8 +785,8 @@ ] }, "Parameter_Block": { - "prefix": "param-block", - "description": "A Parameter block to get you started.", + "prefix": "param-block-advanced-function", + "description": "A parameter block for an advanced function. More: Get-Help about_Functions_Advanced", "body": [ "[CmdletBinding()]", "param (", @@ -858,57 +849,74 @@ "$${3:ParameterName}$0" ] }, - "PesterContext": { - "prefix": "Context-Pester", - "description": "Pester - Context block", - "body": [ - "Context \"${1:ContextName}\" {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "PesterContextIt": { - "prefix": "Context-It-Pester", - "description": "Pester - Context block with nested It block", - "body": [ - "Context \"${1:ContextName}\" {", - "\tIt \"${2:ItName}\" {", - "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", - "\t}$0", - "}" - ] - }, - "PesterDescribeBlock": { - "prefix": "Describe-Pester", - "description": "Pester Describe block", + "Pipeline Function": { + "prefix": "function-pipeline", + "description": "Basic function that accepts pipeline input \nReference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2", "body": [ - "Describe \"${1:DescribeName}\" {", - "\t${0:TM_SELECTED_TEXT}", - "}" - ] - }, - "PesterDescribeContextIt": { - "prefix": "Describe-Context-It-Pester", - "description": "Pester Describe block with nested Context & It blocks", - "body": [ - "Describe \"${1:DescribeName}\" {", - "\tContext \"${2:ContextName}\" {", - "\t\tIt \"${3:ItName}\" {", - "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", - "\t\t}$0", - "\t}", + "function $1 {", + " [CmdletBinding()]", + " param(", + " [parameter(ValueFromPipeline)]$2", + " )", + "", + " process {", + " $0", + " }", "}" ] }, - "PesterIt": { - "prefix": "It-Pester", - "description": "Pester - It block", - "body": [ - "It \"${1:ItName}\" {", - "\t${2:${TM_SELECTED_TEXT:Assertion}}", - "}$0" - ] - }, + // Pester is no longer bundled with PowerShell Core, but is available as a NuGet package. + // "PesterContext": { + // "prefix": "Context-Pester", + // "description": "Pester - Context block", + // "body": [ + // "Context \"${1:ContextName}\" {", + // "\t${0:$TM_SELECTED_TEXT}", + // "}" + // ] + // }, + // "PesterContextIt": { + // "prefix": "Context-It-Pester", + // "description": "Pester - Context block with nested It block", + // "body": [ + // "Context \"${1:ContextName}\" {", + // "\tIt \"${2:ItName}\" {", + // "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", + // "\t}$0", + // "}" + // ] + // }, + // "PesterDescribeBlock": { + // "prefix": "Describe-Pester", + // "description": "Pester Describe block", + // "body": [ + // "Describe \"${1:DescribeName}\" {", + // "\t${0:TM_SELECTED_TEXT}", + // "}" + // ] + // }, + // "PesterDescribeContextIt": { + // "prefix": "Describe-Context-It-Pester", + // "description": "Pester Describe block with nested Context & It blocks", + // "body": [ + // "Describe \"${1:DescribeName}\" {", + // "\tContext \"${2:ContextName}\" {", + // "\t\tIt \"${3:ItName}\" {", + // "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", + // "\t\t}$0", + // "\t}", + // "}" + // ] + // }, + // "PesterIt": { + // "prefix": "It-Pester", + // "description": "Pester - It block", + // "body": [ + // "It \"${1:ItName}\" {", + // "\t${2:${TM_SELECTED_TEXT:Assertion}}", + // "}$0" + // ] + // }, "Property": { "prefix": "prop", "description": "Class property definition snippet", @@ -934,66 +942,6 @@ "#endregion" ] }, - "Requires Assembly": { - "prefix": "requires-assembly", - "description": "Requires an assembly (by name) in order to execute the containing script file.", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'" - }, - "Requires Assembly Path": { - "prefix": "requires-assembly-path", - "description": "Requires an assembly (by relative or absolute path) in order to execute the containing script file.", - "body": "#Requires -Assembly ${0:${TM_SELECTED_TEXT:path/to/assembly.dll}}" - }, - "Requires Assembly Version": { - "prefix": "requires-assembly-version", - "description": "Requires an assembly (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -Assembly '${1:${TM_SELECTED_TEXT:fully-qualified-name}}, Version=${2:1.0.0.0}'" - }, - "Requires Module": { - "prefix": "requires-module", - "description": "Requires a module (by name) in order to execute the containing script file.", - "body": "#Requires -Module ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" - }, - "Requires Module RequiredVersion": { - "prefix": "requires-module-required-version", - "description": "Requires a module (by name and exact version) in order to execute the containing script file.", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; RequiredVersion = '${2:exact-required-version}' }" - }, - "Requires Module Version": { - "prefix": "requires-module-version", - "description": "Requires a module (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -Module @{ ModuleName = '${1:${TM_SELECTED_TEXT:fully-qualified-name}}'; ModuleVersion = '${2:minimum-acceptable-version}' }" - }, - "Requires PSEdition": { - "prefix": "requires-ps-edition", - "description": "Requires a specific edition of PowerShell in order to execute the containing script file.", - "body": "#Requires -PSEdition ${1|Core,Desktop|}" - }, - "Requires PSSnapin": { - "prefix": "requires-ps-snapin", - "description": "Requires a PowerShell snap-in (by name) in order to execute the containing script file.", - "body": "#Requires -PSSnapin ${0:${TM_SELECTED_TEXT:fully-qualified-name}}" - }, - "Requires PSSnapin Version": { - "prefix": "requires-ps-snapin-version", - "description": "Requires a PowerShell snap-in (by name and minimum version) in order to execute the containing script file.", - "body": "#Requires -PSSnapin ${1:${TM_SELECTED_TEXT:fully-qualified-name}} -Version ${2:minimum-acceptable-version}" - }, - "Requires RunAsAdministrator": { - "prefix": "requires-run-as-administrator", - "description": "Requires elevated user rights in order to execute the containing script file. Ignored on non-Windows systems. On Windows systems, it requires that the PowerShell session in which the containing script file is run must have been started with elevated user rights (\"Run as Administrator\").", - "body": "#Requires -RunAsAdministrator" - }, - "Requires ShellId": { - "prefix": "requires-shell-id", - "description": "Requires a specific shell id in order to execute the containing script file. The current shell id may be determined by querying the $ShellId automatic variable.", - "body": "#Requires -ShellId ${0:${TM_SELECTED_TEXT:shell-id}}" - }, - "Requires Version": { - "prefix": "requires-version", - "description": "Requires a minimum version of PowerShell in order to execute the containing script file.", - "body": "#Requires -Version ${0:${TM_SELECTED_TEXT:minimum-acceptable-version}}" - }, "Suppress PSScriptAnalyzer Rule": { "prefix": "suppress-message-rule", "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", @@ -1025,100 +973,96 @@ "}" ] }, + "Ternary Operator": { + "prefix": "ternary", + "description": "[PS 7+] Simplified version of if-else popular in other languages that works in Powershell. More: about_If", + "body": [ + "(${TM_SELECTED_TEXT:${1:condition}}) ? $(${2:actionIfTrue}) : $(${3:actionIfFalse})", + "$0" + ] + }, "try-catch": { - "prefix": "try", - "description": "try-catch snippet", + "prefix": "try-catch", + "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code rather than terminate the program More: about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", "}", "catch {", - "\t", + "\t{1:Do this if a terminating exception happens}", "}" ] }, "try-catch-finally": { - "prefix": "trycf", - "description": "try-catch-finally snippet", + "prefix": "try-catch-finally", + "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code, finally performing a final block of code regardless of the outcome. More: about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", "}", "catch {", - "\t", + "\t{1:Do this if a terminating exception happens}", "}", "finally {", - "\t", + "\t{2:Do this after the try block regardless of whether an exception occurred or not}", "}" ] }, "try-finally": { - "prefix": "tryf", - "description": "try-finally snippet", + "prefix": "try-finally", + "description": "Attempt a block of code and perform an action regardless of the outcome. Useful for cleanup or gracefully disconnecting active sessions even if there was a terminating error. More: about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", "}", "finally {", - "\t", + "\t{2:Do this after the try block regardless of whether an exception occurred or not}", "}" ] }, "while": { "prefix": "while", - "description": "while loop snippet", + "description": "Repeatedly perform an action after verifying a condition is true first.", "body": [ "while (${1:condition}) {", "\t${0:$TM_SELECTED_TEXT}", "}" ] }, - "Workflow": { - "prefix": "workflow", - "description": "workflow snippet", - "body": [ - "workflow ${name:Verb-Noun} {", - "\tparam (", - "\t)", - "", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow ForEachParallel": { - "prefix": "workflow foreach-parallel", - "description": "foreach-parallel snippet (for use inside a workflow)", - "body": [ - "foreach -parallel ($${variable:item} in $${collection:collection}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, - "Workflow InlineScript": { - "prefix": "workflow inlinescript", - "description": "inlinescript snippet (for use inside a workflow)", + "splat": { + "prefix": "splat", + "description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting", "body": [ - "inlineScript {", - "\t${0:$TM_SELECTED_TEXT}", - "}" + "$${1/[^\\w]/_/}Params = @{", + "\t${2:Parameter} = ${0:Value}", + "}", + "${1:${TM_SELECTED_TEXT}} @${1/[^\\w]/_/}Params" ] }, - "Workflow Parallel": { - "prefix": "workflow parallel", - "description": "parallel snippet (for use inside a workflow)", + "Here-String": { + "prefix": [ + "hs", + "here-string" + ], "body": [ - "parallel {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] + "@\"", + "${0:TM_SELECTED_TEXT}", + "\"@", + "" + ], + "description": "Escape all text but evaluate variables. More: Get-Help about_Quoting_Rules" }, - "Workflow Sequence": { - "prefix": "workflow sequence", - "description": "sequence snippet (for use inside a workflow)", + "Here-String (Literal)": { + "prefix": [ + "hsl", + "literal-here-string" + ], "body": [ - "sequence {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] + "@'", + "${0:TM_SELECTED_TEXT}", + "'@", + "" + ], + "description": "Escape all text regardless. More: Get-Help about_Quoting_Rules" } } From 1e1fc4625e711cebbb7d4ebacee7484ebe8dbf87 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sun, 20 Feb 2022 09:34:40 -0800 Subject: [PATCH 09/14] Remove comment about requires --- snippets/PowerShell.json | 1 - 1 file changed, 1 deletion(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 1ac2f997d6..e586007710 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,4 +1,3 @@ -// The "Requires *" snippets should be removed if-and-when intellisense is implemented for the script requirement directive syntax. { "ArgumentCompleterAttribute": { "prefix": "argument-completer", From 6e2f92a94473f84efb7e6ec6b0095117340df6b6 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sun, 20 Feb 2022 11:50:15 -0800 Subject: [PATCH 10/14] More revamp on scriptanalyzer and others --- snippets/PowerShell.json | 130 ++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index e586007710..1ac06076e7 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -25,7 +25,7 @@ "prefix": "calculated-property", "description": "Typically used with Select-Object or Sort-Object. More: Get-Help about_Calculated_Properties", "body": [ - "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:\\$_.PropertyValue}}}}$0" + "@{Name='${1:PropertyName}';Expression={${2:${TM_SELECTED_TEXT:<# Desired result. You can reference this object via \\$_ and \\$PSItem#>}}}}$0 #>" ] }, "Class": { @@ -33,7 +33,7 @@ "description": "A blueprint used to create instances of objects at run time. More: Get-Help about_Classes", "body": [ "class ${1:ClassName} {", - "\t${0:${TM_SELECTED_TEXT:#Define the class. Try constructors, properties, or methods}}", + "\t${0:${TM_SELECTED_TEXT:< #Define the class. Try constructors, properties, or methods #>}}", "}" ] }, @@ -44,8 +44,8 @@ ], "description": "Set default values and validate object logic at the moment of creating the instance of the class. Constructors have the same name as the class. Constructors might have arguments, to initialize the data members of the new object. More: Get-Help about_Classes", "body": [ - "${1:ClassName}(${2:OptionalParameters}) {", - "\t${0:${TM_SELECTED_TEXT:#Initialize the class. Use \\$this to reference the properties of the instance you are creating}}", + "${1:ClassName}(${2:<#OptionalParameters#>}) {", + "\t${0:${TM_SELECTED_TEXT:<# Initialize the class. Use \\$this to reference the properties of the instance you are creating #>}}", "}" ] }, @@ -56,7 +56,7 @@ "description": "A multi-line comment.", "body": [ "$BLOCK_COMMENT_START", - " # ${{0:$TM_SELECTED_TEXT:Enter a comment or description}}", + " # ${0:{$TM_SELECTED_TEXT:Enter a comment or description}}", "$BLOCK_COMMENT_END" ] }, @@ -67,7 +67,7 @@ "do {", "\t${0:$TM_SELECTED_TEXT}", "} until (", - "\t${1:#Condition that stops the loop if it returns true}", + "\t${1:<# Condition that stops the loop if it returns true #>}", ")" ] }, @@ -78,7 +78,7 @@ "do {", "\t${0:$TM_SELECTED_TEXT}", "} while (", - "\t${1:#Condition that stops the loop if it returns false})", + "\t${1:<# Condition that stops the loop if it returns false #>})", ")" ] }, @@ -147,7 +147,7 @@ "description": "else defines what is done when all if and elseif conditions are false. More: Get-Help about_If", "body": [ "else {", - "\t${0:$TM_SELECTED_TEXT}", + "\t${0:${TM_SELECTED_TEXT:<# Action when all if and elseif conditions are false #>}}", "}" ] }, @@ -155,8 +155,8 @@ "prefix": "elseif", "description": "elseif provides an alternative path when an if condition is false. More: Get-Help about_If", "body": [ - "elseif (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", + "elseif (${1:<#condition#>}) {", + "\t${0:${TM_SELECTED_TEXT:<# Action when this condition is true #>}}", "}" ] }, @@ -164,8 +164,8 @@ "prefix": "enum", "description": "An enumeration is a distinct type that consists of a set of named labels called the enumerator list. More: Get-Help about_Enum", "body": [ - "enum ${1:EnumName} {", - "\t${0:$TM_SELECTED_TEXT}", + "enum ${1:<#EnumName#>} {", + "\t${0:${TM_SELECTED_TEXT:<# Specify a list of distinct values #>}}", "}" ] }, @@ -495,10 +495,10 @@ }, "for": { "prefix": "for", - "description": "for loop snippet", + "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the For loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For", "body": [ "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", - "\t${0:$TM_SELECTED_TEXT}", + "\t${0:${TM_SELECTED_TEXT:<# Action that will repeat until the condition is met #>}}", "}" ] }, @@ -507,16 +507,25 @@ "description": "reversed for loop snippet", "body": [ "for ($${1:i} = $${2:array}.Count - 1; $${1:i} -ge 0 ; $${1:i}--) {", - "\t${0:$TM_SELECTED_TEXT}", + "\t${0:${$TM_SELECTED_TEXT}}", "}" ] }, "foreach": { "prefix": "foreach", - "description": "foreach loop snippet", + "description": "Iterate through a collection, assigning a variable to the current item on each loop rather than using the automatic variable $PSItem. More: Get-Help about_Foreach", "body": [ - "foreach ($${1:item} in $${2:collection}) {", - "\t${0:$TM_SELECTED_TEXT}", + "foreach ($${1:currentItemName} in $${2:collection}) {", + "\t${0:${TM_SELECTED_TEXT:<# $${1} is the current item #>}}", + "}" + ] + }, + "foreach-item": { + "prefix": "foreach-item", + "description": "Quicker definition of foreach, just highlight the variable name of the collection you want to use and type 'item' then enter then tab. More: Get-Help about_Foreach", + "body": [ + "foreach (${1/(.*)/$1Item/} in ${1:${TM_SELECTED_TEXT:collection}}) {", + "\t${0:${1/(.*)/$1Item/}}", "}" ] }, @@ -525,7 +534,7 @@ "description": "[PS 7+] Process multiple objects in parallel using runspaces. This has some limitations compared to a regular ForEach-Object. More: Get-Help ForEach-Object", "body": [ "${1:\\$collection} | Foreach-Object -ThrottleLimit ${2:5} -Parallel {", - " ${0:${TM_SELECTED_TEXT:#Reference items via \\$PSItem and bring in outside variables with \\$USING:varname}}", + " ${0:${TM_SELECTED_TEXT:#Action that will run in Parallel. Reference the current object via \\$PSItem and bring in outside variables with \\$USING:varname}}", "}" ] }, @@ -592,25 +601,6 @@ "}" ] }, - "Function-Help": { - "prefix": "help-function", - "description": "Comment-based help for an advanced function snippet", - "body": [ - "<#", - ".SYNOPSIS", - "\t${1:A short one-line action-based description, e.g. 'Tests if a function is valid'}", - ".DESCRIPTION", - "\t${2:A longer description of the function, its purpose, common use cases, etc.}", - ".NOTES", - "\t${3:Information or caveats about the function e.g. 'This function is not supported in Linux'}", - ".LINK", - "\t${4:Specify a URI to a help page, this will show when Get-Help -Online is used.}", - ".EXAMPLE", - "\t${5:Test-MyTestFunction -Verbose}", - "\t${6:Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines}", - "#>" - ] - }, "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", @@ -621,10 +611,7 @@ ] }, "Hashtable": { - "prefix": [ - "Hashtable", - "@{" - ], + "prefix": "Hashtable", "description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables", "body": [ "\\$${1:Var} = @{", @@ -633,7 +620,7 @@ ] }, "Hidden Property": { - "prefix": "class-proph", + "prefix": "class-proph-hidden", "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: about_Hidden", "body": [ "hidden [${1:string}] $${0:PropertyName}" @@ -662,16 +649,16 @@ }, "if": { "prefix": "if", - "description": "if statement snippet", + "description": "Run code blocks if a specified conditional test evaluates to true. More: Get-Help about_If", "body": [ "if (${1:condition}) {", - "\t${0:$TM_SELECTED_TEXT}", + "\t${0:${TM_SELECTED_TEXT:<# Action to perform if the condition is true #>}}", "}" ] }, "IfShouldProcess": { "prefix": "if-Should-Process", - "description": "Creates ShouldProcess block", + "description": "Defines a condition that only executes if -WhatIf is not set, and returns a message otherwise. More: https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess", "body": [ "if (\\$PSCmdlet.ShouldProcess(\"${1:Target}\", \"${2:Operation}\")) {", "\t${0:$TM_SELECTED_TEXT}", @@ -943,28 +930,48 @@ }, "Suppress PSScriptAnalyzer Rule": { "prefix": "suppress-message-rule", - "description": "Suppress a built-in PSScriptAnalyzer rule using the SuppressMessageAttribute", + "description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '')]" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + ")]" ] }, - "Suppress PSScriptAnalyzer Rule in Scope": { - "prefix": "suppress-message-rule-for-scope", - "description": "Suppress a built-in PSScriptAnalyzer rule for functions or classes in a specific scope using the SuppressMessageAttribute", + "Suppress PSScriptAnalyzer Rule in Function": { + "prefix": "suppress-message-rule-function", + "description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSProvideDefaultParameterValue}', '', Scope='Function', Target='${2:*}')]" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", + "\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + ")]" ] }, "Suppress PSScriptAnalyzer Rule on Parameter": { - "prefix": "suppress-message-rule-for-parameter", - "description": "Suppress a built-in PSScriptAnalyzer rule on a parameter using the SuppressMessageAttribute", + "prefix": "suppress-message-rule-parameter", + "description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute('${1:PSUseDeclaredVarsMoreThanAssignments}', '${2:ParamName}')]" + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',", + "\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + ")]" + ] + }, + "Suppress PSScriptAnalyzer Rule on a specific Scope": { + "prefix": "suppress-message-rule-scope", + "description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',", + "\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'", + "\tJustification = '${0:Reason for suppressing}}'", + ")]" ] }, "switch": { "prefix": "switch", - "description": "switch statement snippet", + "description": "Equivalent to a series of if statements, but it is simpler. The switch statement lists each condition and an optional action. If a condition obtains, the action is performed. More: about_Switch", "body": [ "switch (${1:\\$x}) {", "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }", @@ -976,8 +983,7 @@ "prefix": "ternary", "description": "[PS 7+] Simplified version of if-else popular in other languages that works in Powershell. More: about_If", "body": [ - "(${TM_SELECTED_TEXT:${1:condition}}) ? $(${2:actionIfTrue}) : $(${3:actionIfFalse})", - "$0" + "(${1:${TM_SELECTED_TEXT:condition}}) ? $(${2:<#Action if True#>}) : $(${0:<#Action If False#>})" ] }, "try-catch": { @@ -988,7 +994,7 @@ "\t${0:$TM_SELECTED_TEXT}", "}", "catch {", - "\t{1:Do this if a terminating exception happens}", + "\t{1:<#Do this if a terminating exception happens#>}", "}" ] }, @@ -1000,10 +1006,10 @@ "\t${0:$TM_SELECTED_TEXT}", "}", "catch {", - "\t{1:Do this if a terminating exception happens}", + "\t${1:<#Do this if a terminating exception happens#>}", "}", "finally {", - "\t{2:Do this after the try block regardless of whether an exception occurred or not}", + "\t${2:<#Do this after the try block regardless of whether an exception occurred or not#>}", "}" ] }, @@ -1015,7 +1021,7 @@ "\t${0:$TM_SELECTED_TEXT}", "}", "finally {", - "\t{2:Do this after the try block regardless of whether an exception occurred or not}", + "\t${2:<#Do this after the try block regardless of whether an exception occurred or not#>}", "}" ] }, From dd3c09358c228e7b13c3d3269e983a7bee19bef4 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sun, 20 Feb 2022 18:56:32 -0800 Subject: [PATCH 11/14] More cleanup and Sort --- snippets/PowerShell.json | 286 ++++++++++++++++++++------------------- 1 file changed, 149 insertions(+), 137 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 1ac06076e7..4c1ef5352f 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -49,6 +49,74 @@ "}" ] }, + "Class Method": { + "prefix": "class-method", + "description": "Defines the actions that a class can perform. Methods may take parameters that provide input data. Methods can return output. Data returned by a method can be any defined data type. More: Get-Help about_Classes", + "body": [ + "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", + "\t${0:${TM_SELECTED_TEXT:<# Action to perform. You can use $$this to reference the current instance of this class #>}}", + "}" + ] + }, + // Pester is no longer bundled with PowerShell Core, but is available as a NuGet package. + // "PesterContext": { + // "prefix": "Context-Pester", + // "description": "Pester - Context block", + // "body": [ + // "Context \"${1:ContextName}\" {", + // "\t${0:$TM_SELECTED_TEXT}", + // "}" + // ] + // }, + // "PesterContextIt": { + // "prefix": "Context-It-Pester", + // "description": "Pester - Context block with nested It block", + // "body": [ + // "Context \"${1:ContextName}\" {", + // "\tIt \"${2:ItName}\" {", + // "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", + // "\t}$0", + // "}" + // ] + // }, + // "PesterDescribeBlock": { + // "prefix": "Describe-Pester", + // "description": "Pester Describe block", + // "body": [ + // "Describe \"${1:DescribeName}\" {", + // "\t${0:TM_SELECTED_TEXT}", + // "}" + // ] + // }, + // "PesterDescribeContextIt": { + // "prefix": "Describe-Context-It-Pester", + // "description": "Pester Describe block with nested Context & It blocks", + // "body": [ + // "Describe \"${1:DescribeName}\" {", + // "\tContext \"${2:ContextName}\" {", + // "\t\tIt \"${3:ItName}\" {", + // "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", + // "\t\t}$0", + // "\t}", + // "}" + // ] + // }, + // "PesterIt": { + // "prefix": "It-Pester", + // "description": "Pester - It block", + // "body": [ + // "It \"${1:ItName}\" {", + // "\t${2:${TM_SELECTED_TEXT:Assertion}}", + // "}$0" + // ] + // }, + "Class Property": { + "prefix": "class-property", + "description": "Properties are variables declared at class scope. A property may be of any built-in type or an instance of another class. Classes have no restriction in the number of properties they have. More: Get-Help about_Classes", + "body": [ + "[${1:propertyType}] $${0:PropertyName}" + ] + }, "Comment Block": { "prefix": [ "block-comment" @@ -610,6 +678,19 @@ "}" ] }, + "Function: Suppress PSScriptAnalyzer Rule": { + "prefix": [ + "suppress-message-rule-function", + "[SuppressMessageAttribute]" + ], + "description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", + "\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + ")]" + ] + }, "Hashtable": { "prefix": "Hashtable", "description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables", @@ -619,9 +700,35 @@ "}" ] }, + "Here-String": { + "prefix": [ + "hs", + "here-string" + ], + "description": "Escape all text but evaluate variables. More: Get-Help about_Quoting_Rules", + "body": [ + "@\"", + "${0:TM_SELECTED_TEXT}", + "\"@", + "" + ] + }, + "Here-String (Literal)": { + "prefix": [ + "hsl", + "literal-here-string" + ], + "description": "Escape all text regardless. More: Get-Help about_Quoting_Rules", + "body": [ + "@'", + "${0:TM_SELECTED_TEXT}", + "'@", + "" + ] + }, "Hidden Property": { "prefix": "class-proph-hidden", - "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: about_Hidden", + "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: Get-Help about_Hidden", "body": [ "hidden [${1:string}] $${0:PropertyName}" ] @@ -665,15 +772,6 @@ "}" ] }, - "Method": { - "prefix": "method", - "description": "Class method definition snippet", - "body": [ - "[${1:void}] ${2:MethodName}($${3:OptionalParameters}) {", - "\t${0:$TM_SELECTED_TEXT}", - "}" - ] - }, "ModuleManifest": { "prefix": "manifest", "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.", @@ -835,9 +933,22 @@ "$${3:ParameterName}$0" ] }, + "Parameter: Suppress PSScriptAnalyzer Rule": { + "prefix": [ + "suppress-message-rule-parameter", + "[SuppressMessageAttribute]" + ], + "description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "body": [ + "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',", + "\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + ")]" + ] + }, "Pipeline Function": { "prefix": "function-pipeline", - "description": "Basic function that accepts pipeline input \nReference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2", + "description": "Basic function that accepts pipeline input. More: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2", "body": [ "function $1 {", " [CmdletBinding()]", @@ -851,68 +962,12 @@ "}" ] }, - // Pester is no longer bundled with PowerShell Core, but is available as a NuGet package. - // "PesterContext": { - // "prefix": "Context-Pester", - // "description": "Pester - Context block", - // "body": [ - // "Context \"${1:ContextName}\" {", - // "\t${0:$TM_SELECTED_TEXT}", - // "}" - // ] - // }, - // "PesterContextIt": { - // "prefix": "Context-It-Pester", - // "description": "Pester - Context block with nested It block", - // "body": [ - // "Context \"${1:ContextName}\" {", - // "\tIt \"${2:ItName}\" {", - // "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", - // "\t}$0", - // "}" - // ] - // }, - // "PesterDescribeBlock": { - // "prefix": "Describe-Pester", - // "description": "Pester Describe block", - // "body": [ - // "Describe \"${1:DescribeName}\" {", - // "\t${0:TM_SELECTED_TEXT}", - // "}" - // ] - // }, - // "PesterDescribeContextIt": { - // "prefix": "Describe-Context-It-Pester", - // "description": "Pester Describe block with nested Context & It blocks", - // "body": [ - // "Describe \"${1:DescribeName}\" {", - // "\tContext \"${2:ContextName}\" {", - // "\t\tIt \"${3:ItName}\" {", - // "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", - // "\t\t}$0", - // "\t}", - // "}" - // ] - // }, - // "PesterIt": { - // "prefix": "It-Pester", - // "description": "Pester - It block", - // "body": [ - // "It \"${1:ItName}\" {", - // "\t${2:${TM_SELECTED_TEXT:Assertion}}", - // "}$0" - // ] - // }, - "Property": { - "prefix": "prop", - "description": "Class property definition snippet", - "body": [ - "[${1:string}] $${0:PropertyName}" - ] - }, "PSCustomObject": { - "prefix": "[PSCustomObject]", - "description": "Creates a PSCustomObject", + "prefix": [ + "pscustomobject", + "[PSCustomObject]" + ], + "description": "Create a custom object from a hashtable of properties. More: Get-Help about_PSCustomObject", "body": [ "[PSCustomObject]@{", "\t${1:Name} = ${2:Value}", @@ -928,44 +983,37 @@ "#endregion" ] }, - "Suppress PSScriptAnalyzer Rule": { - "prefix": "suppress-message-rule", - "description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", - "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", - "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,", - "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", - ")]" - ] - }, - "Suppress PSScriptAnalyzer Rule in Function": { - "prefix": "suppress-message-rule-function", - "description": "Suppress a PSScriptAnalyzer rule for a function. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "Scope: Suppress PSScriptAnalyzer Rule": { + "prefix": "suppress-message-rule-scope", + "description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", - "\t<#Category#>'${1:PSProvideDefaultParameterValue}', <#CheckId>\\$null, Scope='Function',", - "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',", + "\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'", + "\tJustification = '${0:Reason for suppressing}}'", ")]" ] }, - "Suppress PSScriptAnalyzer Rule on Parameter": { - "prefix": "suppress-message-rule-parameter", - "description": "Suppress a PSScriptAnalyzer rule on a parameter. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "splat": { + "prefix": "splat", + "description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting", "body": [ - "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',", - "\t<#ParameterName#>'${0:${TM_SELECTED_TEXT:ParamName}}", - "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", - ")]" + "$${1/[^\\w]/_/}Params = @{", + "\t${2:Parameter} = ${0:Value}", + "}", + "${1:${TM_SELECTED_TEXT}} @${1/[^\\w]/_/}Params" ] }, - "Suppress PSScriptAnalyzer Rule on a specific Scope": { - "prefix": "suppress-message-rule-scope", - "description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "Suppress PSScriptAnalyzer Rule": { + "prefix": [ + "suppress-message-rule", + "[SuppressMessageAttribute]" + ], + "description": "Suppress a PSScriptAnalyzer rule. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", - "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',", - "\tTarget='${1:${TM_SELECTED_TEXT:RegexOrGlobPatternToMatchName}}'", - "\tJustification = '${0:Reason for suppressing}}'", + "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}',<#CheckId#>\\$null,", + "\tJustification = '${0:${TM_SELECTED_TEXT:Reason for suppressing}}'", ")]" ] }, @@ -1027,47 +1075,11 @@ }, "while": { "prefix": "while", - "description": "Repeatedly perform an action after verifying a condition is true first.", + "description": "Repeatedly perform an action after verifying a condition is true first. More: Get-Help about_While", "body": [ "while (${1:condition}) {", "\t${0:$TM_SELECTED_TEXT}", "}" ] - }, - "splat": { - "prefix": "splat", - "description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting", - "body": [ - "$${1/[^\\w]/_/}Params = @{", - "\t${2:Parameter} = ${0:Value}", - "}", - "${1:${TM_SELECTED_TEXT}} @${1/[^\\w]/_/}Params" - ] - }, - "Here-String": { - "prefix": [ - "hs", - "here-string" - ], - "body": [ - "@\"", - "${0:TM_SELECTED_TEXT}", - "\"@", - "" - ], - "description": "Escape all text but evaluate variables. More: Get-Help about_Quoting_Rules" - }, - "Here-String (Literal)": { - "prefix": [ - "hsl", - "literal-here-string" - ], - "body": [ - "@'", - "${0:TM_SELECTED_TEXT}", - "'@", - "" - ], - "description": "Escape all text regardless. More: Get-Help about_Quoting_Rules" } } From c1c06cac1302c90adb4ea0cd5b55b158392fbd29 Mon Sep 17 00:00:00 2001 From: Justin Grote Date: Sun, 20 Feb 2022 19:05:17 -0800 Subject: [PATCH 12/14] Comment out Examples/DSC/Pester --- snippets/PowerShell.json | 768 +++++++++++++++++++-------------------- 1 file changed, 384 insertions(+), 384 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 4c1ef5352f..812700dced 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -150,66 +150,66 @@ ")" ] }, - "DSC Ensure Enum": { - "prefix": "DSC Ensure enum", - "description": "DSC Ensure enum definition snippet", - "body": [ - "enum Ensure {", - "\tAbsent", - "\tPresent", - "}", - "$0" - ] - }, - "DSC Resource Provider (class-based)": { - "prefix": "DSC resource provider (class-based)", - "description": "Class-based DSC resource provider snippet", - "body": [ - "[DscResource()]", - "class ${ResourceName:NameOfResource} {", - "\t[DscProperty(Key)]", - "\t[string] $${PropertyName:KeyName}", - "\t", - "\t# Gets the resource's current state.", - "\t[${ResourceName:NameOfResource}] Get() {", - "\t\t${0:$TM_SELECTED_TEXT}", - "\t\treturn \\$this", - "\t}", - "\t", - "\t# Sets the desired state of the resource.", - "\t[void] Set() {", - "\t\t", - "\t}", - "\t", - "\t# Tests if the resource is in the desired state.", - "\t[bool] Test() {", - "\t\t", - "\t}", - "}" - ] - }, - "DSC Resource Provider (function-based)": { - "prefix": "DSC resource provider (function-based)", - "description": "Function-based DSC resource provider snippet", - "body": [ - "function Get-TargetResource {", - "\tparam (", - "\t)", - "\t", - "\t${0:$TM_SELECTED_TEXT}", - "}", - "function Set-TargetResource {", - "\tparam (", - "\t)", - "\t", - "}", - "function Test-TargetResource {", - "\tparam (", - "\t)", - "\t", - "}" - ] - }, + // "DSC Ensure Enum": { + // "prefix": "DSC Ensure enum", + // "description": "DSC Ensure enum definition snippet", + // "body": [ + // "enum Ensure {", + // "\tAbsent", + // "\tPresent", + // "}", + // "$0" + // ] + // }, + // "DSC Resource Provider (class-based)": { + // "prefix": "DSC resource provider (class-based)", + // "description": "Class-based DSC resource provider snippet", + // "body": [ + // "[DscResource()]", + // "class ${ResourceName:NameOfResource} {", + // "\t[DscProperty(Key)]", + // "\t[string] $${PropertyName:KeyName}", + // "\t", + // "\t# Gets the resource's current state.", + // "\t[${ResourceName:NameOfResource}] Get() {", + // "\t\t${0:$TM_SELECTED_TEXT}", + // "\t\treturn \\$this", + // "\t}", + // "\t", + // "\t# Sets the desired state of the resource.", + // "\t[void] Set() {", + // "\t\t", + // "\t}", + // "\t", + // "\t# Tests if the resource is in the desired state.", + // "\t[bool] Test() {", + // "\t\t", + // "\t}", + // "}" + // ] + // }, + // "DSC Resource Provider (function-based)": { + // "prefix": "DSC resource provider (function-based)", + // "description": "Function-based DSC resource provider snippet", + // "body": [ + // "function Get-TargetResource {", + // "\tparam (", + // "\t)", + // "\t", + // "\t${0:$TM_SELECTED_TEXT}", + // "}", + // "function Set-TargetResource {", + // "\tparam (", + // "\t)", + // "\t", + // "}", + // "function Test-TargetResource {", + // "\tparam (", + // "\t)", + // "\t", + // "}" + // ] + // }, "else": { "prefix": "else", "description": "else defines what is done when all if and elseif conditions are false. More: Get-Help about_If", @@ -237,330 +237,330 @@ "}" ] }, - "Example-Class": { - "prefix": "ex-class", - "description": "Example: class snippet with a constructor, property and a method", - "body": [ - "class ${1:MyClass} {", - "\t# Property: Holds name", - "\t[String] \\$Name", - "", - "\t# Constructor: Creates a new MyClass object, with the specified name", - "\t${1:MyClass}([String] \\$NewName) {", - "\t\t# Set name for ${1:MyClass}", - "\t\t\\$this.Name = \\$NewName", - "\t}", - "", - "\t# Method: Method that changes \\$Name to the default name", - "\t[void] ChangeNameToDefault() {", - "\t\t\\$this.Name = \"DefaultName\"", - "\t}", - "}" - ] - }, - "Example-Cmdlet": { - "prefix": "ex-cmdlet", - "description": "Example: script cmdlet snippet with all attributes and inline help fields", - "body": [ - "<#", - ".SYNOPSIS", - "\tShort description", - ".DESCRIPTION", - "\tLong description", - ".EXAMPLE", - "\tExample of how to use this cmdlet", - ".EXAMPLE", - "\tAnother example of how to use this cmdlet", - ".INPUTS", - "\tInputs to this cmdlet (if any)", - ".OUTPUTS", - "\tOutput from this cmdlet (if any)", - ".NOTES", - "\tGeneral notes", - ".COMPONENT", - "\tThe component this cmdlet belongs to", - ".ROLE", - "\tThe role this cmdlet belongs to", - ".FUNCTIONALITY", - "\tThe functionality that best describes this cmdlet", - "#>", - "function ${name:Verb-Noun} {", - "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - "\t SupportsShouldProcess=\\$true,", - "\t PositionalBinding=\\$false,", - "\t HelpUri = 'http://www.microsoft.com/',", - "\t ConfirmImpact='Medium')]", - "\t[Alias()]", - "\t[OutputType([String])]", - "\tParam (", - "\t\t# Param1 help description", - "\t\t[Parameter(Mandatory=\\$true,", - "\t\t Position=0,", - "\t\t ValueFromPipeline=\\$true,", - "\t\t ValueFromPipelineByPropertyName=\\$true,", - "\t\t ValueFromRemainingArguments=\\$false, ", - "\t\t ParameterSetName='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", - "\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", - "\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", - "\tbegin {", - "\t}", - "\t", - "\tprocess {", - "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", - "\t\t\t$0", - "\t\t}", - "\t}", - "\t", - "\tend {", - "\t}", - "}" - ] - }, - "Example-DSC Configuration": { - "prefix": "ex-DSC config", - "description": "Example: DSC configuration snippet that uses built-in resource providers", - "body": [ - "configuration Name {", - "\t# One can evaluate expressions to get the node list", - "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", - "\tnode (\"Node1\",\"Node2\",\"Node3\")", - "\t{", - "\t\t# Call Resource Provider", - "\t\t# E.g: WindowsFeature, File", - "\t\tWindowsFeature FriendlyName", - "\t\t{", - "\t\t\tEnsure = \"Present\"", - "\t\t\tName = \"Feature Name\"", - "\t\t}", - "", - "\t\tFile FriendlyName", - "\t\t{", - "\t\t\tEnsure = \"Present\"", - "\t\t\tSourcePath = \\$SourcePath", - "\t\t\tDestinationPath = \\$DestinationPath", - "\t\t\tType = \"Directory\"", - "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", - "\t\t}", - "\t}", - "}" - ] - }, - "Example-DSC Resource Provider (class-based)": { - "prefix": "ex-DSC resource provider (class-based)", - "description": "Example: class-based DSC resource provider snippet", - "body": [ - "# Defines the values for the resource's Ensure property.", - "enum Ensure {", - "\t# The resource must be absent.", - "\tAbsent", - "\t# The resource must be present.", - "\tPresent", - "}", - "", - "# [DscResource()] indicates the class is a DSC resource.", - "[DscResource()]", - "class NameOfResource {", - "\t# A DSC resource must define at least one key property.", - "\t[DscProperty(Key)]", - "\t[string] \\$P1", - "\t", - "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", - "\t[DscProperty(Mandatory)]", - "\t[Ensure] \\$P2", - "\t", - "\t# NotConfigurable properties return additional information about the state of the resource.", - "\t# For example, a Get() method might return the date a resource was last modified.", - "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", - "\t[DscProperty(NotConfigurable)]", - "\t[Nullable[datetime]] \\$P3", - "\t", - "\t[DscProperty()]", - "\t[ValidateSet(\"val1\", \"val2\")]", - "\t[string] \\$P4", - "\t", - "\t# Gets the resource's current state.", - "\t[NameOfResource] Get() {", - "\t\t# NotConfigurable properties are set in the Get method.", - "\t\t\\$this.P3 = something", - "\t\t# Return this instance or construct a new instance.", - "\t\treturn \\$this", - "\t}", - "\t", - "\t# Sets the desired state of the resource.", - "\t[void] Set() {", - "\t}", - "\t", - "\t# Tests if the resource is in the desired state.", - "\t[bool] Test() {", - "\t\t return \\$true", - "\t}", - "}" - ] - }, - "Example-DSC Resource Provider (function based)": { - "prefix": "ex-DSC resource provider (function based)", - "description": "Example: function-based DSC resource provider snippet", - "body": [ - "function Get-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}", - "function Set-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}", - "function Test-TargetResource {", - "\t# TODO: Add parameters here", - "\t# Make sure to use the same parameters for", - "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - "\tparam (", - "\t)", - "}" - ] - }, - "Example-Path Processing for No Wildcards Allowed": { - "prefix": "ex-path processing for no wildcards allowed", - "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - "\\$paths = @()", - "foreach (\\$aPath in \\$Path) {", - "\tif (!(Test-Path -LiteralPath \\$aPath)) {", - "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\tcontinue", - "\t}", - "", - "\t# Resolve any relative paths", - "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Path Processing for Non-Existing Paths": { - "prefix": "ex-path processing for non-existing paths", - "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - "\\$paths = @()", - "foreach (\\$aPath in \\$Path) {", - "\t# Resolve any relative paths", - "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Path Processing for Wildcards Allowed": { - "prefix": "ex-path processing for wildcards allowed", - "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", - "body": [ - "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", - "\\$paths = @()", - "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", - "\tforeach (\\$aPath in \\$Path) {", - "\t\tif (!(Test-Path -Path \\$aPath)) {", - "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\t\tcontinue", - "\t\t}", - "\t", - "\t\t# Resolve any wildcards that might be in the path", - "\t\t\\$provider = \\$null", - "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", - "\t}", - "}", - "else {", - "\tforeach (\\$aPath in \\$LiteralPath) {", - "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", - "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - "\t\t\tcontinue", - "\t\t}", - "\t", - "\t\t# Resolve any relative paths", - "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - "\t}", - "}", - "", - "foreach (\\$aPath in \\$paths) {", - "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - "\t\t# Process each path", - "\t\t$0", - "\t}", - "}" - ] - }, - "Example-Splatting": { - "prefix": "ex-splat", - "description": "Example: PowerShell splatting technique snippet", - "body": [ - "\\$Params = @{", - "\tModule = '*'", - "\tVerb = 'Get'", - "}", - "Get-Command @Params" - ] - }, - "Example-Switch": { - "prefix": "ex-switch", - "description": "Example: switch statement snippet", - "body": [ - "switch (${variable:\\$x})", - "{", - "\t'${val:value1}' { $1 }", - "\t{\\$_ -in 'A','B','C'} {}", - "\t'value3' {}", - "\tDefault {}", - "}" - ] - }, + // "Example-Class": { + // "prefix": "ex-class", + // "description": "Example: class snippet with a constructor, property and a method", + // "body": [ + // "class ${1:MyClass} {", + // "\t# Property: Holds name", + // "\t[String] \\$Name", + // "", + // "\t# Constructor: Creates a new MyClass object, with the specified name", + // "\t${1:MyClass}([String] \\$NewName) {", + // "\t\t# Set name for ${1:MyClass}", + // "\t\t\\$this.Name = \\$NewName", + // "\t}", + // "", + // "\t# Method: Method that changes \\$Name to the default name", + // "\t[void] ChangeNameToDefault() {", + // "\t\t\\$this.Name = \"DefaultName\"", + // "\t}", + // "}" + // ] + // }, + // "Example-Cmdlet": { + // "prefix": "ex-cmdlet", + // "description": "Example: script cmdlet snippet with all attributes and inline help fields", + // "body": [ + // "<#", + // ".SYNOPSIS", + // "\tShort description", + // ".DESCRIPTION", + // "\tLong description", + // ".EXAMPLE", + // "\tExample of how to use this cmdlet", + // ".EXAMPLE", + // "\tAnother example of how to use this cmdlet", + // ".INPUTS", + // "\tInputs to this cmdlet (if any)", + // ".OUTPUTS", + // "\tOutput from this cmdlet (if any)", + // ".NOTES", + // "\tGeneral notes", + // ".COMPONENT", + // "\tThe component this cmdlet belongs to", + // ".ROLE", + // "\tThe role this cmdlet belongs to", + // ".FUNCTIONALITY", + // "\tThe functionality that best describes this cmdlet", + // "#>", + // "function ${name:Verb-Noun} {", + // "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", + // "\t SupportsShouldProcess=\\$true,", + // "\t PositionalBinding=\\$false,", + // "\t HelpUri = 'http://www.microsoft.com/',", + // "\t ConfirmImpact='Medium')]", + // "\t[Alias()]", + // "\t[OutputType([String])]", + // "\tParam (", + // "\t\t# Param1 help description", + // "\t\t[Parameter(Mandatory=\\$true,", + // "\t\t Position=0,", + // "\t\t ValueFromPipeline=\\$true,", + // "\t\t ValueFromPipelineByPropertyName=\\$true,", + // "\t\t ValueFromRemainingArguments=\\$false, ", + // "\t\t ParameterSetName='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", + // "\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", + // "\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", + // "\tbegin {", + // "\t}", + // "\t", + // "\tprocess {", + // "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", + // "\t\t\t$0", + // "\t\t}", + // "\t}", + // "\t", + // "\tend {", + // "\t}", + // "}" + // ] + // }, + // "Example-DSC Configuration": { + // "prefix": "ex-DSC config", + // "description": "Example: DSC configuration snippet that uses built-in resource providers", + // "body": [ + // "configuration Name {", + // "\t# One can evaluate expressions to get the node list", + // "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", + // "\tnode (\"Node1\",\"Node2\",\"Node3\")", + // "\t{", + // "\t\t# Call Resource Provider", + // "\t\t# E.g: WindowsFeature, File", + // "\t\tWindowsFeature FriendlyName", + // "\t\t{", + // "\t\t\tEnsure = \"Present\"", + // "\t\t\tName = \"Feature Name\"", + // "\t\t}", + // "", + // "\t\tFile FriendlyName", + // "\t\t{", + // "\t\t\tEnsure = \"Present\"", + // "\t\t\tSourcePath = \\$SourcePath", + // "\t\t\tDestinationPath = \\$DestinationPath", + // "\t\t\tType = \"Directory\"", + // "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", + // "\t\t}", + // "\t}", + // "}" + // ] + // }, + // "Example-DSC Resource Provider (class-based)": { + // "prefix": "ex-DSC resource provider (class-based)", + // "description": "Example: class-based DSC resource provider snippet", + // "body": [ + // "# Defines the values for the resource's Ensure property.", + // "enum Ensure {", + // "\t# The resource must be absent.", + // "\tAbsent", + // "\t# The resource must be present.", + // "\tPresent", + // "}", + // "", + // "# [DscResource()] indicates the class is a DSC resource.", + // "[DscResource()]", + // "class NameOfResource {", + // "\t# A DSC resource must define at least one key property.", + // "\t[DscProperty(Key)]", + // "\t[string] \\$P1", + // "\t", + // "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", + // "\t[DscProperty(Mandatory)]", + // "\t[Ensure] \\$P2", + // "\t", + // "\t# NotConfigurable properties return additional information about the state of the resource.", + // "\t# For example, a Get() method might return the date a resource was last modified.", + // "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", + // "\t[DscProperty(NotConfigurable)]", + // "\t[Nullable[datetime]] \\$P3", + // "\t", + // "\t[DscProperty()]", + // "\t[ValidateSet(\"val1\", \"val2\")]", + // "\t[string] \\$P4", + // "\t", + // "\t# Gets the resource's current state.", + // "\t[NameOfResource] Get() {", + // "\t\t# NotConfigurable properties are set in the Get method.", + // "\t\t\\$this.P3 = something", + // "\t\t# Return this instance or construct a new instance.", + // "\t\treturn \\$this", + // "\t}", + // "\t", + // "\t# Sets the desired state of the resource.", + // "\t[void] Set() {", + // "\t}", + // "\t", + // "\t# Tests if the resource is in the desired state.", + // "\t[bool] Test() {", + // "\t\t return \\$true", + // "\t}", + // "}" + // ] + // }, + // "Example-DSC Resource Provider (function based)": { + // "prefix": "ex-DSC resource provider (function based)", + // "description": "Example: function-based DSC resource provider snippet", + // "body": [ + // "function Get-TargetResource {", + // "\t# TODO: Add parameters here", + // "\t# Make sure to use the same parameters for", + // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + // "\tparam (", + // "\t)", + // "}", + // "function Set-TargetResource {", + // "\t# TODO: Add parameters here", + // "\t# Make sure to use the same parameters for", + // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + // "\tparam (", + // "\t)", + // "}", + // "function Test-TargetResource {", + // "\t# TODO: Add parameters here", + // "\t# Make sure to use the same parameters for", + // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + // "\tparam (", + // "\t)", + // "}" + // ] + // }, + // "Example-Path Processing for No Wildcards Allowed": { + // "prefix": "ex-path processing for no wildcards allowed", + // "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", + // "body": [ + // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + // "\\$paths = @()", + // "foreach (\\$aPath in \\$Path) {", + // "\tif (!(Test-Path -LiteralPath \\$aPath)) {", + // "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + // "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + // "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + // "\t\t\\$psCmdlet.WriteError(\\$errRecord)", + // "\t\tcontinue", + // "\t}", + // "", + // "\t# Resolve any relative paths", + // "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + // "}", + // "", + // "foreach (\\$aPath in \\$paths) {", + // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + // "\t\t# Process each path", + // "\t\t$0", + // "\t}", + // "}" + // ] + // }, + // "Example-Path Processing for Non-Existing Paths": { + // "prefix": "ex-path processing for non-existing paths", + // "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", + // "body": [ + // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + // "\\$paths = @()", + // "foreach (\\$aPath in \\$Path) {", + // "\t# Resolve any relative paths", + // "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + // "}", + // "", + // "foreach (\\$aPath in \\$paths) {", + // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + // "\t\t# Process each path", + // "\t\t$0", + // "\t}", + // "}" + // ] + // }, + // "Example-Path Processing for Wildcards Allowed": { + // "prefix": "ex-path processing for wildcards allowed", + // "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", + // "body": [ + // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", + // "\\$paths = @()", + // "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", + // "\tforeach (\\$aPath in \\$Path) {", + // "\t\tif (!(Test-Path -Path \\$aPath)) {", + // "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + // "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + // "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + // "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + // "\t\t\tcontinue", + // "\t\t}", + // "\t", + // "\t\t# Resolve any wildcards that might be in the path", + // "\t\t\\$provider = \\$null", + // "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", + // "\t}", + // "}", + // "else {", + // "\tforeach (\\$aPath in \\$LiteralPath) {", + // "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", + // "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + // "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + // "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + // "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + // "\t\t\tcontinue", + // "\t\t}", + // "\t", + // "\t\t# Resolve any relative paths", + // "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + // "\t}", + // "}", + // "", + // "foreach (\\$aPath in \\$paths) {", + // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + // "\t\t# Process each path", + // "\t\t$0", + // "\t}", + // "}" + // ] + // }, + // "Example-Splatting": { + // "prefix": "ex-splat", + // "description": "Example: PowerShell splatting technique snippet", + // "body": [ + // "\\$Params = @{", + // "\tModule = '*'", + // "\tVerb = 'Get'", + // "}", + // "Get-Command @Params" + // ] + // }, + // "Example-Switch": { + // "prefix": "ex-switch", + // "description": "Example: switch statement snippet", + // "body": [ + // "switch (${variable:\\$x})", + // "{", + // "\t'${val:value1}' { $1 }", + // "\t{\\$_ -in 'A','B','C'} {}", + // "\t'value3' {}", + // "\tDefault {}", + // "}" + // ] + // }, "for": { "prefix": "for", "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the For loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For", From c7d39906fd77e063bd3760acbf78f8525230becc Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 4 Mar 2022 16:07:04 -0800 Subject: [PATCH 13/14] Spell check and more Get-Help --- snippets/PowerShell.json | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 812700dced..55a18ababf 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -1,7 +1,7 @@ { "ArgumentCompleterAttribute": { "prefix": "argument-completer", - "description": "Allows you to add tab completion values to a specific parameter by writing a scriptblock that generates zero or more CompletionResult objects. More: Get-Help about_Functions_Argument_Completion", + "description": "Allows you to add tab completion values to a specific parameter by writing a script block that generates zero or more CompletionResult objects. More: Get-Help about_Functions_Argument_Completion", "body": [ "[ArgumentCompleter({", "\t[OutputType([System.Management.Automation.CompletionResult])]", @@ -563,7 +563,7 @@ // }, "for": { "prefix": "for", - "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the For loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For", + "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the for loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For", "body": [ "for ($${1:i} = 0; $${1:i} -lt $${2:array}.Count; $${1:i}++) {", "\t${0:${TM_SELECTED_TEXT:<# Action that will repeat until the condition is met #>}}", @@ -608,7 +608,7 @@ }, "function": { "prefix": "function", - "description": "A simple function with a parameter block to specify function arguments", + "description": "A simple function with a parameter block to specify function arguments. More: Get-Help about_Functions", "body": [ "function ${1:FunctionName} {", "\tparam (", @@ -647,7 +647,7 @@ "function-advanced", "cmdlet" ], - "description": "Script advanced function definition snippet", + "description": "Script advanced function definition snippet. More: Get-Help about_Functions_Advanced", "body": [ "function ${1:Verb-Noun} {", "\t[CmdletBinding()]", @@ -671,7 +671,7 @@ }, "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", + "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", "body": [ "function ${1:FunctionName} (${2:OptionalParameters}) {", "\t${0:$TM_SELECTED_TEXT}", @@ -693,7 +693,7 @@ }, "Hashtable": { "prefix": "Hashtable", - "description": "A key/value store that are very effecient for finding and retrieving data. More: Get-Help about_Hash_Tables", + "description": "A key/value store that are very efficient for finding and retrieving data. More: Get-Help about_Hash_Tables", "body": [ "\\$${1:Var} = @{", "\t${2:Name} = ${3:Value}", @@ -718,7 +718,7 @@ "hsl", "literal-here-string" ], - "description": "Escape all text regardless. More: Get-Help about_Quoting_Rules", + "description": "Escape all text literally. More: Get-Help about_Quoting_Rules", "body": [ "@'", "${0:TM_SELECTED_TEXT}", @@ -728,14 +728,14 @@ }, "Hidden Property": { "prefix": "class-proph-hidden", - "description": "Useful for creating properties and methods within a class that you do not necessarily want other users of the class to see, or readily be able to edit. More: Get-Help about_Hidden", + "description": "Useful for creating internal properties and methods within a class that are hidden from users. More: Get-Help about_Hidden", "body": [ "hidden [${1:string}] $${0:PropertyName}" ] }, "IArgumentCompleter Class": { "prefix": "iargument-completer", - "description": "Implementation of the IArgumentCompleter interface that can be directly attached to parameters (e.g. [MyCustomArgumentCompleter])", + "description": "Implementation of the IArgumentCompleter interface that can be directly attached to parameters (e.g. [MyCustomArgumentCompleter]). More: Get-Help about_Functions_Argument_Completion", "body": [ "class ${1:ArgumentCompleter} : System.Management.Automation.IArgumentCompleter {", "\t[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(", @@ -774,7 +774,7 @@ }, "ModuleManifest": { "prefix": "manifest", - "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata.", + "description": "Basic skeleton for a PowerShell module manifest, complete with PowerShell Gallery metadata. More: https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest", "body": [ "@{", "\t# If authoring a script module, the RootModule is the name of your .psm1 file", @@ -829,14 +829,14 @@ "\t\t}", "\t}", "", - "\t# If your module supports updateable help, what is the URI to the help archive? (optional)", + "\t# If your module supports updatable help, what is the URI to the help archive? (optional)", "\t# HelpInfoURI = ''", "}" ] }, "Parallel Pipeline Function": { "prefix": "function-parallel-pipeline", - "description": "Collects everything in the process block and does work in the end block. Useful when making a 'fan out' function that acts on multiple items simultaneously because the pipeline only does one item at a time in the process block.", + "description": "Collects everything in the process block and does work in the end block. Useful when making a 'fan out' function that acts on multiple items simultaneously because the pipeline only does one item at a time in the process block. More: Get-Help about_Functions_Advanced", "body": [ "function $1 {", " [CmdletBinding()]", @@ -948,7 +948,7 @@ }, "Pipeline Function": { "prefix": "function-pipeline", - "description": "Basic function that accepts pipeline input. More: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.2", + "description": "Basic function that accepts pipeline input. More: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines", "body": [ "function $1 {", " [CmdletBinding()]", @@ -976,7 +976,7 @@ }, "Region Block": { "prefix": "#region", - "description": "Region Block for organizing and folding of your code", + "description": "Region block for organizing and folding of your code", "body": [ "#region ${1}", "${0:$TM_SELECTED_TEXT}", @@ -985,7 +985,7 @@ }, "Scope: Suppress PSScriptAnalyzer Rule": { "prefix": "suppress-message-rule-scope", - "description": "Suppress a PSScriptAnaylzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", + "description": "Suppress a PSScriptAnalyzer rule based on a function/parameter/class/variable/object's name by setting the SuppressMessageAttribute's Target property to a regular expression or a glob pattern. More: https://docs.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/overview?view=ps-modules#suppressing-rules", "body": [ "[Diagnostics.CodeAnalysis.SuppressMessageAttribute(", "\t<#Category#>'${1:PSUseDeclaredVarsMoreThanAssignments}', <#CheckId#>\\$null, Scope='Function',", @@ -996,7 +996,7 @@ }, "splat": { "prefix": "splat", - "description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: about_Splatting", + "description": "Use a hashtable to capture the parameters of a function and then pass them to a function in a concise way. More: Get-Help about_Splatting", "body": [ "$${1/[^\\w]/_/}Params = @{", "\t${2:Parameter} = ${0:Value}", @@ -1019,7 +1019,7 @@ }, "switch": { "prefix": "switch", - "description": "Equivalent to a series of if statements, but it is simpler. The switch statement lists each condition and an optional action. If a condition obtains, the action is performed. More: about_Switch", + "description": "Equivalent to a series of if statements, but it is simpler. The switch statement lists each condition and an optional action. If a condition obtains, the action is performed. More: Get-Help about_Switch", "body": [ "switch (${1:\\$x}) {", "\t${2:condition} { ${0:$TM_SELECTED_TEXT} }", @@ -1029,14 +1029,14 @@ }, "Ternary Operator": { "prefix": "ternary", - "description": "[PS 7+] Simplified version of if-else popular in other languages that works in Powershell. More: about_If", + "description": "[PS 7+] Simplified version of if-else popular in other languages that works in Powershell. More: Get-Help about_If", "body": [ "(${1:${TM_SELECTED_TEXT:condition}}) ? $(${2:<#Action if True#>}) : $(${0:<#Action If False#>})" ] }, "try-catch": { "prefix": "try-catch", - "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code rather than terminate the program More: about_Try_Catch_Finally", + "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code rather than terminate the program More: Get-Help about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", @@ -1048,7 +1048,7 @@ }, "try-catch-finally": { "prefix": "try-catch-finally", - "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code, finally performing a final block of code regardless of the outcome. More: about_Try_Catch_Finally", + "description": "Attempt a block of code and if a terminating exception occurs, perform another block of code, finally performing a final block of code regardless of the outcome. More: Get-Help about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", @@ -1063,7 +1063,7 @@ }, "try-finally": { "prefix": "try-finally", - "description": "Attempt a block of code and perform an action regardless of the outcome. Useful for cleanup or gracefully disconnecting active sessions even if there was a terminating error. More: about_Try_Catch_Finally", + "description": "Attempt a block of code and perform an action regardless of the outcome. Useful for cleanup or gracefully disconnecting active sessions even if there was a terminating error. More: Get-Help about_Try_Catch_Finally", "body": [ "try {", "\t${0:$TM_SELECTED_TEXT}", From ab1e93d8f07a5f3e10137ddb2f8dfdea990f8d70 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 4 Mar 2022 16:23:17 -0800 Subject: [PATCH 14/14] Move commented out snippets to community snippets document --- docs/community_snippets.md | 528 ++++++++++++++++++++++++++++++++++--- snippets/PowerShell.json | 436 ------------------------------ 2 files changed, 497 insertions(+), 467 deletions(-) diff --git a/docs/community_snippets.md b/docs/community_snippets.md index 7d8816d09b..757081d292 100644 --- a/docs/community_snippets.md +++ b/docs/community_snippets.md @@ -2,7 +2,7 @@ > A curated list of awesome vscode snippets for PowerShell. -*Inspired by the [awesome](https://github.com/sindresorhus/awesome) lists, focusing on PowerShell snippets in VSCode* +_Inspired by the [awesome](https://github.com/sindresorhus/awesome) lists, focusing on PowerShell snippets in VSCode_ [![Awesome](https://awesome.re/badge.svg)](https://awesome.re) @@ -18,25 +18,28 @@ _To contribute, check out our [guide here](#contributing)._ | Snippet name | Description | | --------- | ---------| -| [AssertMock](#assert-mock) | _Creates assert mock Pester test_ | +| [AssertMock](#assertmock) | _Creates assert mock Pester test_ | | [AWSRegionDynamicParameter](#awsregiondynamicparameter) | _Creates a dynamic parameter of current AWS regions by @jbruett_ | | [DataTable](#datatable) | _Creates a DataTable_ | | [DateTimeWriteVerbose](#datetimewriteverbose) | _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ | +| [DSC](#dsc) | __DSC snippets previously bundled in extension__ | +| [Examples](#examples) | __Examples previously bundled in extension__ | | [Error-Terminating](#error-terminating) | _Create a full terminating error by @omniomi_ | | [Exchange Online Connection](#exchange-online-connection) | _Create a connection to Exchange Online by @vmsilvamolina_ | | [HTML header](#html-header) | _Add HTML header with the style tag by @vmsilvamolina_ | | [MaxColumnLengthinDataTable](#maxcolumnlengthindatatable) | _Gets the max length of string columns in datatables_ | | [New Azure Resource Group](#new-azure-resource-group) | _Create an Azure Resource group by @vmsilvamolina_ | | [Parameter-Credential](#parameter-credential) | _Add a standard credential parameter to your function by @omniomi_ | +| [Pester](#pester) | __Pester snippets previously bundled in extension__ | | [PesterTestForMandatoryParameter](#pestertestformandatoryparameter) | _Create Pester test for a mandatory parameter_ | | [PesterTestForParameter](#pestertestforparameter) | _Create Pester test for parameter_ | | [Send-MailMessage](#send-mailmessage) | _Send an mail message with the most common parameters by @fullenw1_ | ## Snippets -### Assert Mock +### AssertMock -Creates Assert Mock for Pester Tests y @SQLDBAWithABeard +Creates Assert Mock for Pester Tests by @SQLDBAWithABeard. #### Snippet @@ -57,7 +60,7 @@ Creates Assert Mock for Pester Tests y @SQLDBAWithABeard ### AWSRegionDynamicParameter -Creates a dynamic parameter of the current AWS regions. Includes parameter validation. +Creates a dynamic parameter of the current AWS regions. Includes parameter validation. #### Snippet @@ -139,6 +142,408 @@ Quickly add a `Write-Verbose` with the current date and time inserted before the } ``` +### DSC + +DSC snippets migrated from the extension. + +```json +{ + "DSC Ensure Enum": { + "prefix": "DSC Ensure enum", + "description": "DSC Ensure enum definition snippet", + "body": [ + "enum Ensure {", + "\tAbsent", + "\tPresent", + "}", + "$0" + ] + }, + "DSC Resource Provider (class-based)": { + "prefix": "DSC resource provider (class-based)", + "description": "Class-based DSC resource provider snippet", + "body": [ + "[DscResource()]", + "class ${ResourceName:NameOfResource} {", + "\t[DscProperty(Key)]", + "\t[string] $${PropertyName:KeyName}", + "\t", + "\t# Gets the resource's current state.", + "\t[${ResourceName:NameOfResource}] Get() {", + "\t\t${0:$TM_SELECTED_TEXT}", + "\t\treturn \\$this", + "\t}", + "\t", + "\t# Sets the desired state of the resource.", + "\t[void] Set() {", + "\t\t", + "\t}", + "\t", + "\t# Tests if the resource is in the desired state.", + "\t[bool] Test() {", + "\t\t", + "\t}", + "}" + ] + }, + "DSC Resource Provider (function-based)": { + "prefix": "DSC resource provider (function-based)", + "description": "Function-based DSC resource provider snippet", + "body": [ + "function Get-TargetResource {", + "\tparam (", + "\t)", + "\t", + "\t${0:$TM_SELECTED_TEXT}", + "}", + "function Set-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}", + "function Test-TargetResource {", + "\tparam (", + "\t)", + "\t", + "}" + ] + }, +} +``` + +### Examples + +Example snippets migrated from the extension. + +```json +{ + "Example-Class": { + "prefix": "ex-class", + "description": "Example: class snippet with a constructor, property and a method", + "body": [ + "class ${1:MyClass} {", + "\t# Property: Holds name", + "\t[String] \\$Name", + "", + "\t# Constructor: Creates a new MyClass object, with the specified name", + "\t${1:MyClass}([String] \\$NewName) {", + "\t\t# Set name for ${1:MyClass}", + "\t\t\\$this.Name = \\$NewName", + "\t}", + "", + "\t# Method: Method that changes \\$Name to the default name", + "\t[void] ChangeNameToDefault() {", + "\t\t\\$this.Name = \"DefaultName\"", + "\t}", + "}" + ] + }, + "Example-Cmdlet": { + "prefix": "ex-cmdlet", + "description": "Example: script cmdlet snippet with all attributes and inline help fields", + "body": [ + "<#", + ".SYNOPSIS", + "\tShort description", + ".DESCRIPTION", + "\tLong description", + ".EXAMPLE", + "\tExample of how to use this cmdlet", + ".EXAMPLE", + "\tAnother example of how to use this cmdlet", + ".INPUTS", + "\tInputs to this cmdlet (if any)", + ".OUTPUTS", + "\tOutput from this cmdlet (if any)", + ".NOTES", + "\tGeneral notes", + ".COMPONENT", + "\tThe component this cmdlet belongs to", + ".ROLE", + "\tThe role this cmdlet belongs to", + ".FUNCTIONALITY", + "\tThe functionality that best describes this cmdlet", + "#>", + "function ${name:Verb-Noun} {", + "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", + "\t SupportsShouldProcess=\\$true,", + "\t PositionalBinding=\\$false,", + "\t HelpUri = 'http://www.microsoft.com/',", + "\t ConfirmImpact='Medium')]", + "\t[Alias()]", + "\t[OutputType([String])]", + "\tParam (", + "\t\t# Param1 help description", + "\t\t[Parameter(Mandatory=\\$true,", + "\t\t Position=0,", + "\t\t ValueFromPipeline=\\$true,", + "\t\t ValueFromPipelineByPropertyName=\\$true,", + "\t\t ValueFromRemainingArguments=\\$false, ", + "\t\t ParameterSetName='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", + "\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", + "\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", + "\tbegin {", + "\t}", + "\t", + "\tprocess {", + "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", + "\t\t\t$0", + "\t\t}", + "\t}", + "\t", + "\tend {", + "\t}", + "}" + ] + }, + "Example-DSC Configuration": { + "prefix": "ex-DSC config", + "description": "Example: DSC configuration snippet that uses built-in resource providers", + "body": [ + "configuration Name {", + "\t# One can evaluate expressions to get the node list", + "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", + "\tnode (\"Node1\",\"Node2\",\"Node3\")", + "\t{", + "\t\t# Call Resource Provider", + "\t\t# E.g: WindowsFeature, File", + "\t\tWindowsFeature FriendlyName", + "\t\t{", + "\t\t\tEnsure = \"Present\"", + "\t\t\tName = \"Feature Name\"", + "\t\t}", + "", + "\t\tFile FriendlyName", + "\t\t{", + "\t\t\tEnsure = \"Present\"", + "\t\t\tSourcePath = \\$SourcePath", + "\t\t\tDestinationPath = \\$DestinationPath", + "\t\t\tType = \"Directory\"", + "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", + "\t\t}", + "\t}", + "}" + ] + }, + "Example-DSC Resource Provider (class-based)": { + "prefix": "ex-DSC resource provider (class-based)", + "description": "Example: class-based DSC resource provider snippet", + "body": [ + "# Defines the values for the resource's Ensure property.", + "enum Ensure {", + "\t# The resource must be absent.", + "\tAbsent", + "\t# The resource must be present.", + "\tPresent", + "}", + "", + "# [DscResource()] indicates the class is a DSC resource.", + "[DscResource()]", + "class NameOfResource {", + "\t# A DSC resource must define at least one key property.", + "\t[DscProperty(Key)]", + "\t[string] \\$P1", + "\t", + "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", + "\t[DscProperty(Mandatory)]", + "\t[Ensure] \\$P2", + "\t", + "\t# NotConfigurable properties return additional information about the state of the resource.", + "\t# For example, a Get() method might return the date a resource was last modified.", + "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", + "\t[DscProperty(NotConfigurable)]", + "\t[Nullable[datetime]] \\$P3", + "\t", + "\t[DscProperty()]", + "\t[ValidateSet(\"val1\", \"val2\")]", + "\t[string] \\$P4", + "\t", + "\t# Gets the resource's current state.", + "\t[NameOfResource] Get() {", + "\t\t# NotConfigurable properties are set in the Get method.", + "\t\t\\$this.P3 = something", + "\t\t# Return this instance or construct a new instance.", + "\t\treturn \\$this", + "\t}", + "\t", + "\t# Sets the desired state of the resource.", + "\t[void] Set() {", + "\t}", + "\t", + "\t# Tests if the resource is in the desired state.", + "\t[bool] Test() {", + "\t\t return \\$true", + "\t}", + "}" + ] + }, + "Example-DSC Resource Provider (function based)": { + "prefix": "ex-DSC resource provider (function based)", + "description": "Example: function-based DSC resource provider snippet", + "body": [ + "function Get-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}", + "function Set-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}", + "function Test-TargetResource {", + "\t# TODO: Add parameters here", + "\t# Make sure to use the same parameters for", + "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", + "\tparam (", + "\t)", + "}" + ] + }, + "Example-Path Processing for No Wildcards Allowed": { + "prefix": "ex-path processing for no wildcards allowed", + "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + "\\$paths = @()", + "foreach (\\$aPath in \\$Path) {", + "\tif (!(Test-Path -LiteralPath \\$aPath)) {", + "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\tcontinue", + "\t}", + "", + "\t# Resolve any relative paths", + "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Path Processing for Non-Existing Paths": { + "prefix": "ex-path processing for non-existing paths", + "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", + "\\$paths = @()", + "foreach (\\$aPath in \\$Path) {", + "\t# Resolve any relative paths", + "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Path Processing for Wildcards Allowed": { + "prefix": "ex-path processing for wildcards allowed", + "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", + "body": [ + "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", + "\\$paths = @()", + "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", + "\tforeach (\\$aPath in \\$Path) {", + "\t\tif (!(Test-Path -Path \\$aPath)) {", + "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\t\tcontinue", + "\t\t}", + "\t", + "\t\t# Resolve any wildcards that might be in the path", + "\t\t\\$provider = \\$null", + "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", + "\t}", + "}", + "else {", + "\tforeach (\\$aPath in \\$LiteralPath) {", + "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", + "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", + "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", + "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", + "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", + "\t\t\tcontinue", + "\t\t}", + "\t", + "\t\t# Resolve any relative paths", + "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", + "\t}", + "}", + "", + "foreach (\\$aPath in \\$paths) {", + "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", + "\t\t# Process each path", + "\t\t$0", + "\t}", + "}" + ] + }, + "Example-Splatting": { + "prefix": "ex-splat", + "description": "Example: PowerShell splatting technique snippet", + "body": [ + "\\$Params = @{", + "\tModule = '*'", + "\tVerb = 'Get'", + "}", + "Get-Command @Params" + ] + }, + "Example-Switch": { + "prefix": "ex-switch", + "description": "Example: switch statement snippet", + "body": [ + "switch (${variable:\\$x})", + "{", + "\t'${val:value1}' { $1 }", + "\t{\\$_ -in 'A','B','C'} {}", + "\t'value3' {}", + "\tDefault {}", + "}" + ] + }, +} +``` + ### Error-Terminating Quickly add a fully defined error record and throw. by @omniomi @@ -162,7 +567,7 @@ Quickly add a fully defined error record and throw. by @omniomi ### Exchange Online Connection -Connect to Exchange Online, by @vmsilvamolina +Connect to Exchange Online, by @vmsilvamolina. #### Snippet @@ -212,7 +617,7 @@ Add HTML header to a variable with the style tag (for css). ### MaxColumnLengthinDataTable -Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads into a SQL Server table with fixed column widths by @SQLDBAWithABeard +Takes a datatable object and iterates through it to get the max length of the string columns - useful for data loads into a SQL Server table with fixed column widths by @SQLDBAWithABeard. #### Snippet @@ -254,7 +659,7 @@ Create a Resource Group on Azure, by @vmsilvamolina. ### Parameter-Credential -Add a `-Credential` parameter that supports a PSCredential object in a variable, `-Credential (Get-Credential)`, or `-Credential Username` (will prompt). Includes an empty PSCredential object as the default value but this is the first tabstop so pressing backspace after inserting the snippet removes it. by @omniomi +Add a `-Credential` parameter that supports a PSCredential object in a variable, `-Credential (Get-Credential)`, or `-Credential Username` (will prompt). Includes an empty PSCredential object as the default value but this is the first tabstop so pressing backspace after inserting the snippet removes it, by @omniomi. #### Snippet @@ -273,9 +678,69 @@ Add a `-Credential` parameter that supports a PSCredential object in a variable, } ``` +### Pester + +Pester snippets migrated from the extension. + +```json +{ + "PesterContext": { + "prefix": "Context-Pester", + "description": "Pester - Context block", + "body": [ + "Context \"${1:ContextName}\" {", + "\t${0:$TM_SELECTED_TEXT}", + "}" + ] + }, + "PesterContextIt": { + "prefix": "Context-It-Pester", + "description": "Pester - Context block with nested It block", + "body": [ + "Context \"${1:ContextName}\" {", + "\tIt \"${2:ItName}\" {", + "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", + "\t}$0", + "}" + ] + }, + "PesterDescribeBlock": { + "prefix": "Describe-Pester", + "description": "Pester Describe block", + "body": [ + "Describe \"${1:DescribeName}\" {", + "\t${0:TM_SELECTED_TEXT}", + "}" + ] + }, + "PesterDescribeContextIt": { + "prefix": "Describe-Context-It-Pester", + "description": "Pester Describe block with nested Context & It blocks", + "body": [ + "Describe \"${1:DescribeName}\" {", + "\tContext \"${2:ContextName}\" {", + "\t\tIt \"${3:ItName}\" {", + "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", + "\t\t}$0", + "\t}", + "}" + ] + }, + "PesterIt": { + "prefix": "It-Pester", + "description": "Pester - It block", + "body": [ + "It \"${1:ItName}\" {", + "\t${2:${TM_SELECTED_TEXT:Assertion}}", + "}$0" + ] + } +} +``` + ### PesterTestForMandatoryParameter -Quickly create a Pester Test for existence of a mandatory parameter by @SQLDBAWithABeard +Quickly create a Pester Test for existence of a mandatory parameter by @SQLDBAWithABeard. #### Snippet @@ -293,7 +758,7 @@ Quickly create a Pester Test for existence of a mandatory parameter by @SQLDBAWi ### PesterTestForParameter -Quickly create a Pester Test for existence of a parameter by @SQLDBAWithABeard +Quickly create a Pester Test for existence of a parameter by @SQLDBAWithABeard. #### Snippet @@ -316,36 +781,37 @@ Add the Send-MailMessage cmdlet with the most common parameters in a hashtable f #### Snippet ```json -"ex-Send-MailMessage": { - "prefix": "ex-Send-MailMessage", - "body": [ - "$$Params = @{", - " 'SmtpServer' = 'smtp.mycompany.com'", - " 'Port' = 25", - " 'Priority' = 'Normal'", - " 'From' = 'sender@mycompany.com'", - " 'To' = 'mainrecipient@mycompany.com'", - " 'Cc' = 'copyrecipient@mycompany.com'", - " 'Bcc' = 'hiddenrecipient@mycompany.com'", - " 'Subject' = 'Mail title'", - " 'Body' = 'This is the content of my mail'", - " 'BodyAsHtml' = $$false", - " 'Attachments' = 'c:\\MyFile.txt'", - "}", - "Send-MailMessage @Params" - ], - "description": "Send a mail message" +"ex-Send-MailMessage": { + "prefix": "ex-Send-MailMessage", + "body": [ + "$$Params = @{", + " 'SmtpServer' = 'smtp.mycompany.com'", + " 'Port' = 25", + " 'Priority' = 'Normal'", + " 'From' = 'sender@mycompany.com'", + " 'To' = 'mainrecipient@mycompany.com'", + " 'Cc' = 'copyrecipient@mycompany.com'", + " 'Bcc' = 'hiddenrecipient@mycompany.com'", + " 'Subject' = 'Mail title'", + " 'Body' = 'This is the content of my mail'", + " 'BodyAsHtml' = $$false", + " 'Attachments' = 'c:\\MyFile.txt'", + "}", + "Send-MailMessage @Params" + ], + "description": "Send a mail message" } ``` ## Contributing To optimize snippet usability and discoverability for end users we will only ship snippets in the extension which we believe meet the following requirements: + - Must be broadly applicable to most PowerShell extension users -- Must be substantially different from existing snippets or intellisense +- Must be substantially different from existing snippets or intellisense - Must not violate any intellectual property rights -If your snippet does not meet these requirements but would still be useful to customers we will include it in our list of [Awesome Community Snippets](https://github.com/PowerShell/vscode-powershell/blob/master/docs/community_snippets.md). Additionally, snippet creators can publish snippet libraries as standalone extensions in the [VSCode Marketplace](https://code.visualstudio.com/api/working-with-extensions/publishing-extension). +If your snippet does not meet these requirements but would still be useful to customers we will include it in our list of [Awesome Community Snippets](https://github.com/PowerShell/vscode-powershell/blob/master/docs/community_snippets.md). Additionally, snippet creators can publish snippet libraries as standalone extensions in the [VSCode Marketplace](https://code.visualstudio.com/api/working-with-extensions/publishing-extension). If you'd like a snippet to be considered for addition to the list, [open a pull request](https://opensource.guide/how-to-contribute/#opening-a-pull-request) with the following changes: diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index 55a18ababf..c2c84641f2 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -58,58 +58,6 @@ "}" ] }, - // Pester is no longer bundled with PowerShell Core, but is available as a NuGet package. - // "PesterContext": { - // "prefix": "Context-Pester", - // "description": "Pester - Context block", - // "body": [ - // "Context \"${1:ContextName}\" {", - // "\t${0:$TM_SELECTED_TEXT}", - // "}" - // ] - // }, - // "PesterContextIt": { - // "prefix": "Context-It-Pester", - // "description": "Pester - Context block with nested It block", - // "body": [ - // "Context \"${1:ContextName}\" {", - // "\tIt \"${2:ItName}\" {", - // "\t\t${3:${TM_SELECTED_TEXT:Assertion}}", - // "\t}$0", - // "}" - // ] - // }, - // "PesterDescribeBlock": { - // "prefix": "Describe-Pester", - // "description": "Pester Describe block", - // "body": [ - // "Describe \"${1:DescribeName}\" {", - // "\t${0:TM_SELECTED_TEXT}", - // "}" - // ] - // }, - // "PesterDescribeContextIt": { - // "prefix": "Describe-Context-It-Pester", - // "description": "Pester Describe block with nested Context & It blocks", - // "body": [ - // "Describe \"${1:DescribeName}\" {", - // "\tContext \"${2:ContextName}\" {", - // "\t\tIt \"${3:ItName}\" {", - // "\t\t\t${4:${TM_SELECTED_TEXT:Assertion}}", - // "\t\t}$0", - // "\t}", - // "}" - // ] - // }, - // "PesterIt": { - // "prefix": "It-Pester", - // "description": "Pester - It block", - // "body": [ - // "It \"${1:ItName}\" {", - // "\t${2:${TM_SELECTED_TEXT:Assertion}}", - // "}$0" - // ] - // }, "Class Property": { "prefix": "class-property", "description": "Properties are variables declared at class scope. A property may be of any built-in type or an instance of another class. Classes have no restriction in the number of properties they have. More: Get-Help about_Classes", @@ -150,66 +98,6 @@ ")" ] }, - // "DSC Ensure Enum": { - // "prefix": "DSC Ensure enum", - // "description": "DSC Ensure enum definition snippet", - // "body": [ - // "enum Ensure {", - // "\tAbsent", - // "\tPresent", - // "}", - // "$0" - // ] - // }, - // "DSC Resource Provider (class-based)": { - // "prefix": "DSC resource provider (class-based)", - // "description": "Class-based DSC resource provider snippet", - // "body": [ - // "[DscResource()]", - // "class ${ResourceName:NameOfResource} {", - // "\t[DscProperty(Key)]", - // "\t[string] $${PropertyName:KeyName}", - // "\t", - // "\t# Gets the resource's current state.", - // "\t[${ResourceName:NameOfResource}] Get() {", - // "\t\t${0:$TM_SELECTED_TEXT}", - // "\t\treturn \\$this", - // "\t}", - // "\t", - // "\t# Sets the desired state of the resource.", - // "\t[void] Set() {", - // "\t\t", - // "\t}", - // "\t", - // "\t# Tests if the resource is in the desired state.", - // "\t[bool] Test() {", - // "\t\t", - // "\t}", - // "}" - // ] - // }, - // "DSC Resource Provider (function-based)": { - // "prefix": "DSC resource provider (function-based)", - // "description": "Function-based DSC resource provider snippet", - // "body": [ - // "function Get-TargetResource {", - // "\tparam (", - // "\t)", - // "\t", - // "\t${0:$TM_SELECTED_TEXT}", - // "}", - // "function Set-TargetResource {", - // "\tparam (", - // "\t)", - // "\t", - // "}", - // "function Test-TargetResource {", - // "\tparam (", - // "\t)", - // "\t", - // "}" - // ] - // }, "else": { "prefix": "else", "description": "else defines what is done when all if and elseif conditions are false. More: Get-Help about_If", @@ -237,330 +125,6 @@ "}" ] }, - // "Example-Class": { - // "prefix": "ex-class", - // "description": "Example: class snippet with a constructor, property and a method", - // "body": [ - // "class ${1:MyClass} {", - // "\t# Property: Holds name", - // "\t[String] \\$Name", - // "", - // "\t# Constructor: Creates a new MyClass object, with the specified name", - // "\t${1:MyClass}([String] \\$NewName) {", - // "\t\t# Set name for ${1:MyClass}", - // "\t\t\\$this.Name = \\$NewName", - // "\t}", - // "", - // "\t# Method: Method that changes \\$Name to the default name", - // "\t[void] ChangeNameToDefault() {", - // "\t\t\\$this.Name = \"DefaultName\"", - // "\t}", - // "}" - // ] - // }, - // "Example-Cmdlet": { - // "prefix": "ex-cmdlet", - // "description": "Example: script cmdlet snippet with all attributes and inline help fields", - // "body": [ - // "<#", - // ".SYNOPSIS", - // "\tShort description", - // ".DESCRIPTION", - // "\tLong description", - // ".EXAMPLE", - // "\tExample of how to use this cmdlet", - // ".EXAMPLE", - // "\tAnother example of how to use this cmdlet", - // ".INPUTS", - // "\tInputs to this cmdlet (if any)", - // ".OUTPUTS", - // "\tOutput from this cmdlet (if any)", - // ".NOTES", - // "\tGeneral notes", - // ".COMPONENT", - // "\tThe component this cmdlet belongs to", - // ".ROLE", - // "\tThe role this cmdlet belongs to", - // ".FUNCTIONALITY", - // "\tThe functionality that best describes this cmdlet", - // "#>", - // "function ${name:Verb-Noun} {", - // "\t[CmdletBinding(DefaultParameterSetName='Parameter Set 1',", - // "\t SupportsShouldProcess=\\$true,", - // "\t PositionalBinding=\\$false,", - // "\t HelpUri = 'http://www.microsoft.com/',", - // "\t ConfirmImpact='Medium')]", - // "\t[Alias()]", - // "\t[OutputType([String])]", - // "\tParam (", - // "\t\t# Param1 help description", - // "\t\t[Parameter(Mandatory=\\$true,", - // "\t\t Position=0,", - // "\t\t ValueFromPipeline=\\$true,", - // "\t\t ValueFromPipelineByPropertyName=\\$true,", - // "\t\t ValueFromRemainingArguments=\\$false, ", - // "\t\t ParameterSetName='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", - // "\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", - // "\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", - // "\tbegin {", - // "\t}", - // "\t", - // "\tprocess {", - // "\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", - // "\t\t\t$0", - // "\t\t}", - // "\t}", - // "\t", - // "\tend {", - // "\t}", - // "}" - // ] - // }, - // "Example-DSC Configuration": { - // "prefix": "ex-DSC config", - // "description": "Example: DSC configuration snippet that uses built-in resource providers", - // "body": [ - // "configuration Name {", - // "\t# One can evaluate expressions to get the node list", - // "\t# E.g: \\$AllNodes.Where(\"Role -eq Web\").NodeName", - // "\tnode (\"Node1\",\"Node2\",\"Node3\")", - // "\t{", - // "\t\t# Call Resource Provider", - // "\t\t# E.g: WindowsFeature, File", - // "\t\tWindowsFeature FriendlyName", - // "\t\t{", - // "\t\t\tEnsure = \"Present\"", - // "\t\t\tName = \"Feature Name\"", - // "\t\t}", - // "", - // "\t\tFile FriendlyName", - // "\t\t{", - // "\t\t\tEnsure = \"Present\"", - // "\t\t\tSourcePath = \\$SourcePath", - // "\t\t\tDestinationPath = \\$DestinationPath", - // "\t\t\tType = \"Directory\"", - // "\t\t\tDependsOn = \"[WindowsFeature]FriendlyName\"", - // "\t\t}", - // "\t}", - // "}" - // ] - // }, - // "Example-DSC Resource Provider (class-based)": { - // "prefix": "ex-DSC resource provider (class-based)", - // "description": "Example: class-based DSC resource provider snippet", - // "body": [ - // "# Defines the values for the resource's Ensure property.", - // "enum Ensure {", - // "\t# The resource must be absent.", - // "\tAbsent", - // "\t# The resource must be present.", - // "\tPresent", - // "}", - // "", - // "# [DscResource()] indicates the class is a DSC resource.", - // "[DscResource()]", - // "class NameOfResource {", - // "\t# A DSC resource must define at least one key property.", - // "\t[DscProperty(Key)]", - // "\t[string] \\$P1", - // "\t", - // "\t# Mandatory indicates the property is required and DSC will guarantee it is set.", - // "\t[DscProperty(Mandatory)]", - // "\t[Ensure] \\$P2", - // "\t", - // "\t# NotConfigurable properties return additional information about the state of the resource.", - // "\t# For example, a Get() method might return the date a resource was last modified.", - // "\t# NOTE: These properties are only used by the Get() method and cannot be set in configuration.", - // "\t[DscProperty(NotConfigurable)]", - // "\t[Nullable[datetime]] \\$P3", - // "\t", - // "\t[DscProperty()]", - // "\t[ValidateSet(\"val1\", \"val2\")]", - // "\t[string] \\$P4", - // "\t", - // "\t# Gets the resource's current state.", - // "\t[NameOfResource] Get() {", - // "\t\t# NotConfigurable properties are set in the Get method.", - // "\t\t\\$this.P3 = something", - // "\t\t# Return this instance or construct a new instance.", - // "\t\treturn \\$this", - // "\t}", - // "\t", - // "\t# Sets the desired state of the resource.", - // "\t[void] Set() {", - // "\t}", - // "\t", - // "\t# Tests if the resource is in the desired state.", - // "\t[bool] Test() {", - // "\t\t return \\$true", - // "\t}", - // "}" - // ] - // }, - // "Example-DSC Resource Provider (function based)": { - // "prefix": "ex-DSC resource provider (function based)", - // "description": "Example: function-based DSC resource provider snippet", - // "body": [ - // "function Get-TargetResource {", - // "\t# TODO: Add parameters here", - // "\t# Make sure to use the same parameters for", - // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - // "\tparam (", - // "\t)", - // "}", - // "function Set-TargetResource {", - // "\t# TODO: Add parameters here", - // "\t# Make sure to use the same parameters for", - // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - // "\tparam (", - // "\t)", - // "}", - // "function Test-TargetResource {", - // "\t# TODO: Add parameters here", - // "\t# Make sure to use the same parameters for", - // "\t# Get-TargetResource, Set-TargetResource, and Test-TargetResource", - // "\tparam (", - // "\t)", - // "}" - // ] - // }, - // "Example-Path Processing for No Wildcards Allowed": { - // "prefix": "ex-path processing for no wildcards allowed", - // "description": "Example: processing non-wildcard paths that must exist (for use in process block). See parameter-path snippets.", - // "body": [ - // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - // "\\$paths = @()", - // "foreach (\\$aPath in \\$Path) {", - // "\tif (!(Test-Path -LiteralPath \\$aPath)) {", - // "\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - // "\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - // "\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - // "\t\t\\$psCmdlet.WriteError(\\$errRecord)", - // "\t\tcontinue", - // "\t}", - // "", - // "\t# Resolve any relative paths", - // "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - // "}", - // "", - // "foreach (\\$aPath in \\$paths) {", - // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - // "\t\t# Process each path", - // "\t\t$0", - // "\t}", - // "}" - // ] - // }, - // "Example-Path Processing for Non-Existing Paths": { - // "prefix": "ex-path processing for non-existing paths", - // "description": "Example: processing non-existing paths typically used in New-* commands (for use in process block). See parameter-path snippet.", - // "body": [ - // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true)]", - // "\\$paths = @()", - // "foreach (\\$aPath in \\$Path) {", - // "\t# Resolve any relative paths", - // "\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - // "}", - // "", - // "foreach (\\$aPath in \\$paths) {", - // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - // "\t\t# Process each path", - // "\t\t$0", - // "\t}", - // "}" - // ] - // }, - // "Example-Path Processing for Wildcards Allowed": { - // "prefix": "ex-path processing for wildcards allowed", - // "description": "Example: processing wildcard paths that must exist (for use in process block). See parameter-path-wildcards and parameter-literalpath snippets.", - // "body": [ - // "# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=\\$true, DefaultParameterSetName='Path')]", - // "\\$paths = @()", - // "if (\\$psCmdlet.ParameterSetName -eq 'Path') {", - // "\tforeach (\\$aPath in \\$Path) {", - // "\t\tif (!(Test-Path -Path \\$aPath)) {", - // "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - // "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - // "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - // "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - // "\t\t\tcontinue", - // "\t\t}", - // "\t", - // "\t\t# Resolve any wildcards that might be in the path", - // "\t\t\\$provider = \\$null", - // "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(\\$aPath, [ref]\\$provider)", - // "\t}", - // "}", - // "else {", - // "\tforeach (\\$aPath in \\$LiteralPath) {", - // "\t\tif (!(Test-Path -LiteralPath \\$aPath)) {", - // "\t\t\t\\$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '\\$aPath' because it does not exist.\"", - // "\t\t\t\\$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound", - // "\t\t\t\\$errRecord = New-Object System.Management.Automation.ErrorRecord \\$ex,'PathNotFound',\\$category,\\$aPath", - // "\t\t\t\\$psCmdlet.WriteError(\\$errRecord)", - // "\t\t\tcontinue", - // "\t\t}", - // "\t", - // "\t\t# Resolve any relative paths", - // "\t\t\\$paths += \\$psCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\\$aPath)", - // "\t}", - // "}", - // "", - // "foreach (\\$aPath in \\$paths) {", - // "\tif (\\$pscmdlet.ShouldProcess(\\$aPath, 'Operation')) {", - // "\t\t# Process each path", - // "\t\t$0", - // "\t}", - // "}" - // ] - // }, - // "Example-Splatting": { - // "prefix": "ex-splat", - // "description": "Example: PowerShell splatting technique snippet", - // "body": [ - // "\\$Params = @{", - // "\tModule = '*'", - // "\tVerb = 'Get'", - // "}", - // "Get-Command @Params" - // ] - // }, - // "Example-Switch": { - // "prefix": "ex-switch", - // "description": "Example: switch statement snippet", - // "body": [ - // "switch (${variable:\\$x})", - // "{", - // "\t'${val:value1}' { $1 }", - // "\t{\\$_ -in 'A','B','C'} {}", - // "\t'value3' {}", - // "\tDefault {}", - // "}" - // ] - // }, "for": { "prefix": "for", "description": "Creates a loop that runs commands in a command block while a specified condition evaluates to $true. A typical use of the for loop is to iterate an array of values and to operate on a subset of these values. More: Get-Help about_For",