The main idea of this post is to gather a lot of Open Source tools together to check the Quality of PowerShell scripts and provide Code Coverage based on PowerShell Unit Tests.

In my job, in order to manage a Microsoft 365 environments, it is necessary to use PowerShell to:

  • Access all features, even those which are not visible from the Admin UI
  • Implement Continuous Deployment
  • "Package" a set of configurations
  • Automation
  • etc.

When developers develop, it exists some tools to ensure the quality of their code and perform Code Coverage. So why don't we do this with PowerShell scripts? Do some equivalent tools exist to check the PowerShell scripts and perform a Code Coverage? The answer is YES! πŸ™ŒπŸ» Ok, so let's go.

In addition to gather all of these tools together, I list the prerequisites and the information about the usage of them with personal feedback on their capabilities and efficiency.

PowerShell Scripts Overview

To be able to create reports of Code Quality and efficient Code Coverage for your scripts, you have to follow some Best Practices that are almost all illustrated in the Microsoft documentation:

Cmdlet Overview - PowerShell
Cmdlet Overview

Code Coverage

Pester

Pester Code Coverage console result

This is certainly the only tool that allows performing real code coverages:

  • Very similar to Jest and Mocha for React/JavaScript (SPFx)
  • A lot of samples and documentations
  • Exists for a couple of years
  • Relatively easy to use
  • Enough options to use it from the developer computer and from pipelines
Pester - The ubiquitous test and mock framework for PowerShell | Pester
Pester is the ubiquitous test and mock framework for PowerShell

You may also be interested in