Command Line Interface (CLI)
Complete documentation for using the HardenSys CLI tool for automation and scripting.
Overview
The HardenSys CLI tool provides a command-line interface for running security compliance checks, generating reports, and managing Windows security policies. It's perfect for automation, scripting, and integration into CI/CD pipelines.
Key Features
- Run all compliance checks or filter by category
- Generate text or JSON reports
- Administrator privilege detection
- Progress tracking and detailed output
- Export results to files
- Search and filter parameters
Basic Usage
Running All Checks
The simplest way to use the CLI is to run all compliance checks:
python HardenSys.py
On Windows, you can also run: py HardenSys.py
python3 HardenSys.py
On Linux, you may need to use: python3
instead of python
Getting Help
View all available options and examples:
python HardenSys.py --help
Listing Available Categories
See all available security categories and their parameter counts:
python HardenSys.py --list
Filtering Options
Filter by Heading
Run checks for a specific security category:
# Run only Account Policies checks
python HardenSys.py --heading "Account Policies"
# Run only Security Options checks
python HardenSys.py --heading "Security Options"
Filter by Subheading
Run checks for a specific subcategory:
# Run only Password Policy checks
python HardenSys.py --subheading "Password Policy"
# Run only User Rights Assignment checks
python HardenSys.py --subheading "User Rights Assignment"
Filter by Parameter
Run a specific task by its title name:
# Run specific password history check
python HardenSys.py --parameter "Enforce password history"
# Run specific password length check
python HardenSys.py --parameter "Minimum password length"
Show Parameter Information
Get detailed information about parameters, subheadings, or headings:
# Show all password-related tasks
python HardenSys.py --info "password"
# Show all tasks in Account Policies
python HardenSys.py --info "Account Policies"
# Show specific task details
python HardenSys.py --info "Enforce password history"
Report Generation
Text Reports
Generate a text report and save it to a file:
# Generate text report
python HardenSys.py --output report.txt
# Generate report for specific category
python HardenSys.py --heading "Account Policies" --output account_policies.txt
JSON Reports
Generate a JSON report for programmatic processing:
# Generate JSON report
python HardenSys.py --format json --output report.json
# Generate JSON report for specific category
python HardenSys.py --heading "Security Options" --format json --output security_options.json
Report Formats
Both text and JSON formats provide comprehensive compliance information:
Text Report Example
Windows Security Compliance Report
========================================
Generated: 2024-01-15 14:30:25
Duration: 45.67 seconds
Total Checks: 121
Successful: 115
Failed: 6
Success Rate: 95.0%
Detailed Results:
========================================
Account Policies
----------------
✓ Enforce password history
Status: success
Message: ✓ Password history set to 24 successfully
Previous: 0 passwords
Current: 24 passwords
JSON Report Example
{
"summary": {
"total_checks": 121,
"successful_checks": 115,
"failed_checks": 6,
"success_rate": "95.0%",
"duration_seconds": 45.67,
"timestamp": "2024-01-15T14:30:25"
},
"results": [
{
"status": "success",
"message": "✓ Password history set to 24 successfully",
"previous": "0 passwords",
"current": "24 passwords",
"heading": "Account Policies",
"subheading": "Password Policy",
"title": "Enforce password history",
"script_key": "enforce_password_history",
"timestamp": "2024-01-15T14:30:25"
}
]
}
Usage Examples
Quick Security Check
python HardenSys.py --heading "Account Policies" --output quick_check.txt
Full Audit with JSON Export
python HardenSys.py --format json --output full_audit.json
Password Policy Only
python HardenSys.py --subheading "Password Policy" --verbose
Specific Task Check
python HardenSys.py --parameter "Enforce password history" --output password_history_check.txt
Firewall Configuration Check
python HardenSys.py --heading "Windows Defender Firewall with Advanced Security"
PowerShell Integration
# Run all checks
.\HardenSys.ps1
# Run specific category
.\HardenSys.ps1 -Heading "Account Policies"
# Generate JSON report
.\HardenSys.ps1 -Format json -Output "compliance_report.json"
# List categories
.\HardenSys.ps1 -List
Troubleshooting
Common Issues
1. "Not running as Administrator"
To run as Administrator:
- Command Prompt: Right-click Command Prompt → "Run as administrator"
- PowerShell: Right-click PowerShell → "Run as administrator"
- Batch File: Right-click
HardenSys.bat
→ "Run as administrator"
2. "Function not found"
windows_tasks.py
is in the same directory and contains the required function.
3. "JSON file not found"
windows_tasks.json
is in the same directory or use the --json
option to specify a custom path.
4. Import errors
Error Codes
Exit Code | Description |
---|---|
0 | Success |
1 | Error (file not found, import error, etc.) |
Getting Help
If you encounter issues not covered here:
- Check the FAQ section
- Review the Error Codes reference
- Open an issue on GitHub