Posted in Editor, Powershell, vscode

Snippets – A Lesson Learned

Not the  first and probably won’t be the last but since I was talking about VSCode snippets. I started working on one for creating a [Parameter] statement to make building a Param() section easier. Was cool to provide a dropdown box for a variable (so lesson learned but not the subject of this) and now it is time to test it.

First debug, for that list of choices… at first I had |True,False| but I found using |$True,$False| just looked better, personal choice. Testing continues. Part of the snippet includes [VariableType]$variablename. A possible variable type is “PSObject” but looking at the snippet this should work right?

<div>
<div>        // General Parameter Definition</div>
<div>        "Parameter Statement": {</div>
<div>            "prefix": "paramStatement",</div>
<div>            "body": [</div>
<div>                "[parameter(Mandatory=${1|$True,$False|}, ValueFromPipeline=${2|$True,$False|})]\r",</div>
<div>                "\t\tHelpMessage = \"${3:HelpMessage}\")]\r",</div>
<div>                "[${4:VariableType}]$${5:VariableName}"</div>
<div>            ],</div>
<div>            "description": "Scaffold for Parameter creation"</div>
<div>        }</div>
</div>

I would type PSObect and the snippet menu would come up as I type pso… Ugggh. Then it dawns on me I had created a snippet months ago for creating Custom PS Objects and the prefix was … psobj. Lesson Learned, even Snippets have reserved words 🙂 !

Author:

USMC, CVID, Technology, PowerShell... just general ramblings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s