API Reference
Get-PowerShellCompatibility
Analyzes PowerShell files and folders to determine compatibility with Windows PowerShell 5.1 and PowerShell 7+.
Remarks
Scans PowerShell files to detect patterns and constructs that can cause cross-version issues (Windows PowerShell 5.1 vs PowerShell 7+), and outputs a compatibility report. Use this as part of CI to keep modules compatible across editions, and pair it with encoding/line-ending checks when supporting Windows PowerShell 5.1.
Examples
Analyze a module folder
PS>
Get-PowerShellCompatibility -Path 'C:\MyModule'
Analyzes PowerShell files in the folder and returns a compatibility report.
Recursively analyze and include detailed findings
PS>
Get-PowerShellCompatibility -Path 'C:\MyModule' -Recurse -ShowDetails
Useful when investigating why a module behaves differently in PS 5.1 vs PS 7+.
Export compatibility findings to CSV
PS>
Get-PowerShellCompatibility -Path 'C:\MyModule' -ExportPath 'C:\Reports\compatibility.csv'
Creates a report that can be attached to CI artifacts.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.
Syntax
Get-PowerShellCompatibility [-ExcludeDirectories <String[]>] [-ExportPath <String>] [-Internal] -Path <String> [-Recurse] [-ShowDetails] [<CommonParameters>]
#
All Parameter SetsParameters
- ExcludeDirectories String[]
- Directory names to exclude from analysis.
- ExportPath String
- Export the detailed report to a CSV file at the specified path.
- Internal SwitchParameter
- Internal mode used by build pipelines to suppress host output.
- Path String
- Path to the file or directory to analyze for PowerShell compatibility.
- Recurse SwitchParameter
- When analyzing a directory, recursively analyze all subdirectories.
- ShowDetails SwitchParameter
- Include detailed analysis of each file with specific compatibility issues found.
Outputs
System.Object