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”Uses Pester discovery to enumerate all tests under the provided path and returns a list of objects containing:
TestName - Name of the It test. FilePath - Full path to the test file. Describe - Name of the parent Describe block. Tags - Tags explicitly set on the test. CombinedTags - Combination of Describe and Tags (unique, case-insensitive).
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: (Resolve-Path -LiteralPath (Join-Path -Path $PSScriptRoot '..\..' 'tests')).PathAccept 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+.