Skip to content
Andrew Davidson edited this page Jan 27, 2021 · 7 revisions

Usage

Import the module

Import-Module -Name PSQualityCheck

File checks

To check a single file

Invoke-PSQualityCheck -File 'C:\Scripts\Script.ps1'

To check multiple files

Invoke-PSQualityCheck -File @('C:\Scripts\Script.ps1', 'C:\Scripts\Script.ps1')

To check the file C:\Scripts\Script.ps1 including the extra PSScriptAnalyzer rules

Invoke-PSQualityCheck -File 'C:\Scripts\Script.ps1' -ScriptAnalyzerRulesPath 'C:\ScriptAnalyzerRulesPath'

Path checks

To check the folder C:\Scripts

Invoke-PSQualityCheck -Path 'C:\Scripts'

To check the folder C:\Scripts and all subfolders beneath it

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse

To check the folders C:\Scripts and C:\MoreScripts

Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts')

To check the folders C:\Scripts and C:\MoreScripts' and all subfolders beneath both folders

Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts') -Recurse

Specifying alternative Help Rules

Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts') -Recurse -HelpRulesPath 'C:\HelpRules\HelpRules.psd1'

Including and Excluding tests

Tags are available For Module Tests and For Script Tests

To check the folder C:\Scripts and all subfolders beneath it and run only the "ValidSyntax" test

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -Include "ValidSyntax"

To check the folder C:\Scripts and all subfolders beneath it and run the "ValidSyntax" and "NoScriptAnalyzerFailures" tests

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -Include "ValidSyntax", "NoScriptAnalyzerFailures"

To check the folder C:\Scripts and all subfolders beneath it and run all tests but exclude the "ValidSyntax" test

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -Exclude "ValidSyntax"

To check the folder C:\Scripts and all subfolders beneath it and run all tests but exclude the "ValidSyntax" and "NoScriptAnalyzerFailures" tests

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -Exclude "ValidSyntax", "NoScriptAnalyzerFailures"

Getting results

To check the folder C:\Scripts and all subfolders beneath it and display a summary of the checks performed on screen

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -ShowCheckResults

output below uses sample data:

Test                            Files Tested Total Passed Failed Skipped
----                            ------------ ----- ------ ------ -------
Module Tests                               3    21     20      1       0
Extracting functions                       3     3      3      0       0
Extracted function script tests           13   195     64    114      17
Script Tests                              17   255     78    152      25
Total                                     33   474    165    267      42

To check the folder C:\Scripts and all subfolders beneath it and return the pester test objects

$result = Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -Passthru

The $result variable is an object with one or more Pester Test Result Objects that are accessible via the object e.g. $result.Script would return the script Pester Test Result Object

To check the folder C:\Scripts and all subfolders beneath it and export the test results

Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse -ExportCheckResults

this will place the test results (as XML files) in the current directory

Project checks

To check the path C:\Scripts as a project

Invoke-PSQualityCheck -ProjectPath 'C:\Scripts'

the -Passthru, -ExportCheckResults and -ShowCheckResults are also available for use.

Clone this wiki locally