Add detailed AD user statistics script with error handling#9
Open
Frafou wants to merge 1 commit intoTorxed:masterfrom
Open
Add detailed AD user statistics script with error handling#9Frafou wants to merge 1 commit intoTorxed:masterfrom
Frafou wants to merge 1 commit intoTorxed:masterfrom
Conversation
refactor: Overhaul AD user statistics script with comprehensive improvements MAJOR CHANGES: - Refactored v1.0.0 to v2.2.0 with significant enhancements CODE QUALITY IMPROVEMENTS: - Standardized function names to PascalCase (get-ageindays → Get-AgeInDays) - Added comprehensive error handling with try-catch blocks throughout - Implemented proper parameter validation with ValidateNotNullOrEmpty - Organized code into logical regions (#region Functions, Variables, Main) - Fixed function call/parameter mismatches and case sensitivity issues - Removed code duplication and improved reusability FUNCTIONAL ENHANCEMENTS: - Automatic output directory creation if it doesn't exist - Performance optimization: selective AD property queries instead of -Property * - Proper null handling for PasswordLastSet (returns "Never" instead of errors) - Added domain auto-detection fallback with error handling - Module import safety check before loading ActiveDirectory - Graceful handling of empty AD result sets ERROR HANDLING & REPORTING: - Defined exit codes for different error scenarios: - 0: Success, 1: Unexpected error, 2: OS incompatible - 3: Domain retrieval failed, 4: Directory validation failed - 5: User statistics retrieval failed - Added meaningful error messages with stack traces - Fixed undefined script variables ($ErrorCount, $WarningCount, $SuccessCount) - Corrected domain admin count status checking logic DOCUMENTATION: - Expanded parameter documentation with types and examples - Added 4 practical usage examples including -Verbose and -WhatIf variants - Comprehensive PREREQUISITES section with execution policy guidance - Detailed HOWTO section with quick start and advanced usage - Added Exit Codes reference table - Complete issues fixed changelog for each version - Multiple LINK references to official Microsoft documentation OUTPUT & UX: - Added colored console output for better readability - Execution time tracking and display - Improved formatting with headers and separators - Better status messages with checkmarks and warnings - Fixed invalid Write-Host -Level parameter issues - Cleaner, more professional output structure TECHNICAL FIXES: - Fixed improper region nesting in try-catch-finally structure - Removed timestamp expression from default parameter (reliability issue) - Changed domain admin count error return from 0 to -1 for proper validation - Fixed OS detection regex pattern (Windows 1* → Windows (10|11|Server)) - Added proper null/empty string handling throughout BACKWARDS COMPATIBILITY: - Maintains same parameter names and defaults - CSV output format unchanged (semicolon-delimited) - Same column names (Name, AccountAge, PasswordAge) - Compatible with Windows 10, 11, and Windows Server VERSION HISTORY: - v2.0.0: Added comprehensive header (previous release) - v2.1.0: Corrected function conventions and error handling - v2.2.0: Fixed remaining issues and refined implementation TESTING RECOMMENDATIONS: - Verify on Windows 10, 11, and Windows Server environments - Test with -Verbose flag for diagnostic output - Confirm CSV export with different output paths - Validate against multiple AD domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: Overhaul AD user statistics script with comprehensive improvements
MAJOR CHANGES:
CODE QUALITY IMPROVEMENTS:
FUNCTIONAL ENHANCEMENTS:
ERROR HANDLING & REPORTING:
DOCUMENTATION:
OUTPUT & UX:
TECHNICAL FIXES:
BACKWARDS COMPATIBILITY:
VERSION HISTORY:
TESTING RECOMMENDATIONS: