In the past couple of months, I have been busy at work setting up the guidelines for PowerShell development across my company, while refactoring several PowerShell codebases to the latest community practices. As part of this ongoing process, I have learned a lot of new things and faced several unexpected challenges :).
This relatively short post is about highlighting what I consider should be the minimum required tools any software developer, sysadmin or IT professional should use in order to produce high-quality PowerShell code.
Pester
As it is said in the GitHub repository, Pester is the ubiquitous test and mock framework. It has become the facto standard for testing in Powershell and it follows a BDD testing approach. Among its features are mocking support, file system isolation, code coverage metrics and integration with CI systems.
At work, we are currently increasing our usage of Pester and I even recently wrote a module with some custom functions to facilitate tests invocations in our CI system.
Useful links
Github Page A custom Pester framework Why should I care The Pester story
PSScriptAnalyzer
PSScriptAnalyzer is a static code checker for PowerShell code. It verifies that the code conforms with a set of rules. This rules are based on PowerShell best practices developed over the years by the PowerShell team and the community. Integrating it as part of CI/CD setup helps to maintain coding style in a project.
We have integrated the static code checker in our internal projects and it has been truly beneficial to help team members discuss and then agreed in our internal coding rules for PowerShell.
Useful links
Invoke-Build
Invoke-Build is an automation tool used to build and test PowerShell scripts. It predicates the use of tasks as main units of work and provides all the common features in a build automation tool such as tasks dependency, single invocation for tasks, incremental tasks and persistent builds.
The power of Invoke-Build lies in that allows to have an independent build pipeline process, so we are able to complete run all the CI/CD process locally as well as remote using our Jenkins servers.
Useful links
Github Page A Getting Started post
Plaster
Plaster is a template-based generator. The main purpose is to streamline and standardize the creation of PowerShell module projects, tests and build pipelines.
Once we introduced into our design, it has been much easier to agree in a common structure to develop our PowerShell modules, with means, it is now easier for people to collaborate in multiple projects.
Useful links
Github Page Working with Plaster GetPlastered
PlatyPS
PlatyPS is a help generation tool using Markdown to host the help files. It supports multiple scenarios, such as creating docs from scratch by parsing comment-based help documentation, parsing MAML schema or XML or just writing directly the Markdown docs.
The resulting documentation is nicely generated and we are currently using it to automatically update our repos docs in Bitbucket, so anyone can find the documentation online.
Useful links
Github Page Adding Help with PlatyPS
Conclusions
After several trials and error, I can say with confidence that these tools make me a better PowerShell developer, from covering my logic with the tests to seamlessly running the whole CI/CD pipeline from the tips of my finger in the console. And the learning experience of how to use these tools have also had the nice side effect of increasing my understanding of the quirks and code styles across the PowerShell community.
I am just really beginning my PowerShell journey and I look forward to continue it with these tools already under my belt :). If you are just starting with PowerShell don’t be afraid to check them out and have fun!
Thank you so much for reading this post. Hope it has been helpful for you and has pointed you in the right direction. Stay tuned for more!!