PowerShell function for creating a PowerShell function template

A couple of weeks ago I published a blog article “PowerShell function for creating a script module template” and I thought I would follow-up that article with the same type of function for creating a PowerShell function template. Instead of having to remember things like checking to make sure an approved verb is used, that a Pester test is created, and comment based help is entered in the right format, a template such as the one shown in the following code example can make your life much simpler.

When the function is run, two files are created. One for the function containing the template code and one for the Pester test:


Sure, PSScriptAnalyzer or a Pester test could be used to make sure that things like an approved verb are used but both of those options are reactive instead of proactive. If I ended up using an unapproved verb initially until I used one of those tools, I may have hard coded it all over the place so why not treat things like using an approved verb kind of like parameter validation. Don’t allow the user to continue until valid input (an approved verb in this case) is provided instead of finding the problem in hindsight.

The function shown in this blog article is a work in progress and can be downloaded from my PowerShell repository on GitHub. Feel free to fork the repository and submit pull requests if you can think of improvements that could be made to the code.


Leave a Reply

%d bloggers like this: