Get-MtTestInventory
Synopsis
Section titled “Synopsis”Discover Pester test inventory and associated tags.
Syntax
Section titled “Syntax”Get-MtTestInventory [-Path <String>] [-ExcludePath <String[]>] [-ExcludeTag <String[]>] [-OutputType <String>] [-ExportPath <String>] [-PassThru] [-ProgressAction <ActionPreference>] [<CommonParameters>]Description
Section titled “Description”Reads the native tests (Test.<ID>.ps1) and Pester-format tests (*.Tests.ps1) under the provided path without running them, and returns a list of objects containing:
TestName - Name of the It test, or ‘<Id>: <Title>’ of a native test. FilePath - Full path to the test file. Describe - Name of the parent Describe block. For a native test, its Feature. Tags - Tags explicitly set on the test. For a native test, the tags that -Tag matches: the tags it carries and, for a test that ships with Maester, its ID and the tags it carried in Maester 2.x. CombinedTags - Combination of Describe and Tags (unique, case-insensitive).
This command is kept for one major version for scripts written for Maester 2.x. Get-MtTest lists the native tests with their typed attributes (Product, Feature, Area, Severity and the rest).
Examples
Section titled “Examples”Example 1
Section titled “Example 1”$TestInventory = Get-MtTestInventory -Path .\ -ExcludePath .\test-resultsGet an inventory of tests in the current directory and exclude anything in the ‘test-results’ sub-directory.
Example 2
Section titled “Example 2”$TagInventory = Get-MtTestInventory$TagInventory['CIS']Get test test inventory and show tests with the ‘CIS’ tag.
Example 3
Section titled “Example 3”$Tags = Get-MtTestInventory$Tags -notmatch 'AzureConfig|CIS|CISA|Maester|MT.\d{4,5}|ORCA'Show all tags used that do not match the specified tag patterns.
Example 4
Section titled “Example 4”$TagInventory = Get-MtTestInventory$TagInventory.Keys -notmatch 'AzureConfig|CIS|CISA|Maester|MT.\d{4,5}|ORCA'foreach ($i in $TagInventory.GetEnumerator()) { if ($i.Key -notmatch ‘AzureConfig|CIS|CISA|Maester|MT.\d{4,5}|ORCA’) { $i } }
Show all tags used that do not match the specified tag patterns, along with their test objects.
Parameters
Section titled “Parameters”Root path containing the test files. Defaults to the ’..\tests’ directory in the current location.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: (Get-MtMaesterTestFolderPath)Accept pipeline input: FalseAccept wildcard characters: False-ExcludePath
Section titled “-ExcludePath”One or more paths to exclude (e.g. ‘test-results’ directory). Accepts wildcard patterns and relative paths.
Type: String[]Parameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ExcludeTag
Section titled “-ExcludeTag”One or more tags to exclude from discovery.
Type: String[]Parameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: False-OutputType
Section titled “-OutputType”Specify a desired output type for the test inventory:
- Default: Returns the test inventory as objects.
- JSON: Returns the test inventory as a JSON string.
- CSV: Returns the test inventory as a CSV string.
- TagsOnly: Returns only the unique tags found in the test inventory.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: DefaultAccept pipeline input: FalseAccept wildcard characters: False-ExportPath
Section titled “-ExportPath”Path for exported CSV or JSON file. Defaults to ‘TestInventory’ in the current directory.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: (Join-Path -Path $PWD -ChildPath 'TestInventory')Accept pipeline input: FalseAccept wildcard characters: False-PassThru
Section titled “-PassThru”When specified, the test inventory object is returned to the pipeline along with exporting to file.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-ProgressAction
Section titled “-ProgressAction”Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by Write-Progress.
Type: ActionPreferenceParameter Sets: (All)Aliases: proga
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: FalseCommonParameters
Section titled “CommonParameters”This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
Section titled “Inputs”Outputs
Section titled “Outputs”[Ordered] (Default) - An ordered dictionary containing a list of tags and associated test inventory objects.
Section titled “[Ordered] (Default) - An ordered dictionary containing a list of tags and associated test inventory objects.”[String] - JSON string of test inventory (when OutputType is ‘JSON’).
Section titled “[String] - JSON string of test inventory (when OutputType is ‘JSON’).”[String] - CSV string of test inventory (when OutputType is ‘CSV’).
Section titled “[String] - CSV string of test inventory (when OutputType is ‘CSV’).”[String[]] - Array of unique tags (when OutputType is ‘TagsOnly’).
Section titled “[String[]] - Array of unique tags (when OutputType is ‘TagsOnly’).”Requires Pester 5+.