PSRule
PSRule copied to clipboard
Add CLI tool to extract rule information with JSON output
This PR adds a new get rule command to the PSRule CLI tool that extracts rule metadata and outputs it in JSON format for pipeline automation.
What's Changed
-
New CLI Command: Added
ps-rule get rulecommand with comprehensive options - JSON Output: Returns structured JSON perfect for CI/CD pipeline consumption
- Rule Metadata: Extracts tags, labels, annotations, severity, synopsis, description, and recommendations
-
Command Options: Supports
--path,--module,--name,--baseline,--include-dependencies,--no-restore - Tests: Added unit tests to verify command functionality
Usage
# Basic usage - get all rules
ps-rule get rule
# Get specific rules with dependencies
ps-rule get rule --include-dependencies --name "Security.*" --path ./rules
# Get rules from specific modules
ps-rule get rule --module MyModule.Rules --baseline Production
JSON Output Structure
{
"rules": [
{
"ruleName": "Security.TLS",
"displayName": "Use TLS 1.2+",
"synopsis": "Ensure TLS 1.2 or higher is used",
"description": "TLS versions below 1.2 have known vulnerabilities",
"recommendation": "Configure services to use TLS 1.2 or higher",
"moduleName": "Security.Rules",
"severity": "High",
"tags": { "category": "Security", "type": "Protocol" },
"annotations": { "version": "1.0.0", "author": "Security Team" },
"labels": { "environment": "Production" }
}
]
}
Benefits for Pipeline Automation
This command enables easy programmatic access to rule information for:
- Build and release automation scripts
- Copilot actions that need rule metadata
- CI/CD pipelines that process rule information
- Custom tooling that works with PSRule data
The JSON output format makes it simple to consume rule metadata in any language or tool that can parse JSON.
Fixes #2977.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.