Skip to content

Conversation

@ojopiyo
Copy link

@ojopiyo ojopiyo commented Dec 11, 2025

Changes Made in the Refactored Script

  1. Modular Design - Introduced a Set-RetentionLabel function to handle each list item, improving readability, testability, and ease of extension.

  2. Retention Label Mapping Hashtable - Replaced multiple if/elseif statements with a hashtable ($RetentionLabelMapping), making it simple to add or update labels.

  3. Early List Filtering - Only retrieves and processes lists of type GenericList or DocumentLibrary, reducing unnecessary iterations.

  4. Improved Output Readability - Standardized Write-Host messages with consistent formatting and color coding for better visibility during execution.

  5. Error Handling for Missing Fields - Skips lists that do not contain the _ComplianceTag field, preventing runtime errors.

  6. Flattened Loops - Reduced nesting in loops, making the code easier to read, maintain, and debug.

Changes Made in the Refactored Script

1. Modular Design - Introduced a Set-RetentionLabel function to handle each list item, improving readability, testability, and ease of extension.

2. Retention Label Mapping Hashtable - Replaced multiple if/elseif statements with a hashtable ($RetentionLabelMapping), making it simple to add or update labels.

3. Early List Filtering - Only retrieves and processes lists of type GenericList or DocumentLibrary, reducing unnecessary iterations.

4. Improved Output Readability - Standardized Write-Host messages with consistent formatting and color coding for better visibility during execution.

5. Error Handling for Missing Fields - Skips lists that do not contain the _ComplianceTag field, preventing runtime errors.

6. Flattened Loops - Reduced nesting in loops, making the code easier to read, maintain, and debug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant