Config/vscode-snippets.json

{
    "functionJaap": {
        "prefix": "function",
        "body": [
            "",
            "Class ValidateSet : System.Management.Automation.IValidateSetValuesGenerator {",
            " [string[]] GetValidValues() {",
            " $$Values = Get-Command",
            " return [string[]] $$Values",
            " }",
            "}",
            "",
            "",
            "function Verb-Noun {",
            " [CmdletBinding()]",
            " param (",
            " [Parameter(Mandatory)] [ValidateSet(\"Appels\", \"Peren\")] [string] $$ParameterName,",
            " [Parameter(Mandatory = $$true)]",
            " [ArgumentCompleter( {",
            " param ( $$commandName, $$parameterName, $$wordToComplete, $$commandAst, $$fakeBoundParameters )",
            " Get-ChildItem \"$$(Path)$$wordToComplete*\" -Directory -Name | ForEach-Object { \"`\"$$_`\"\" } }",
            " )]",
            " [ValidateScript( {",
            " $$_ -in (Get-ChildItem \"$$(Path)\" -Directory -Name)",
            " } ) ]",
            " [string] $$Parameter2,",
            " [Parameter()] [ValidateSet([ValidateSet])] [string] $$ParameterValidateClass,",
            " [Parameter()] [string] $$ParameterArgumentCompleter",
            " )",
            "",
            "}",
            "",
            "",
            "$$scriptblock = {",
            " param($$commandName, $$parameterName, $$wordToComplete, $$commandAst, $$fakeBoundParameters)",
            " $$o = Get-VM | Where-Object { $$_.Name -like \"$$wordToComplete*\" }",
            " $$o.Name | ForEach-Object {",
            " if ($$_ -match \" \") {",
            " \"'$$_'\"",
            " } else {",
            " $$_",
            " }",
            " }",
            "}",
            "Register-ArgumentCompleter -CommandName Verb-Noun -ParameterName ParameterArgumentCompleter -ScriptBlock $$scriptblock",
            "",
            ""
        ],
        "description": "Create function"
    }
}