2025-05-05 01:50:06 +00:00
2025-05-05 09:32:33 +08:00
2025-05-05 01:29:01 +00:00
2025-05-05 01:50:06 +00:00

Add-RecurseSecurityGroup

A powershell script which adds a security group to a folder and all subfiles and folders.

To be used when subfolders have inheritance disabled but you still need to apply a security group to all.

IMPORTANT: This script has not been thoroughly tested yet, proceed with caution.

The script will:

  • Process all files and folders recursively
  • Apply the specified permissions with the security group
  • Handle objects with disabled inheritance
  • Log all actions to both console (with colors) and log file

Script Features:

  • Color-coded console output (Green for INFO, Yellow for WARNING, Red for ERROR)
  • Comprehensive logging to C:\Logs\ApplySecurityGroup with DD-MM-YYYY date format
  • Parameter validation for folder existence, group validity, and permission types
  • Progress tracking and summary reporting
  • Error handling for individual items (won't stop on single failure)
  • The script will continue processing even if some items fail, and provide a summary of successes and failures at the end.

Example Console Output:

05-05-2025 14:30:15 INFO: Starting security group application process
05-05-2025 14:30:15 INFO: Target Folder: C:\Shared\BiscuitTin
05-05-2025 14:30:15 INFO: Security Group: KITCHEN\FS - RO - Shares - Biscuit Tin
05-05-2025 14:30:15 INFO: Permission: Read
05-05-2025 14:30:17 INFO: Found 12 folders and 47 files to process
05-05-2025 14:30:17 INFO: Applied permissions to folder: C:\Shared\BiscuitTin\Recipes
05-05-2025 14:30:17 INFO: Applied permissions to folder: C:\Shared\BiscuitTin\Financial
05-05-2025 14:30:18 WARNING: Failed to apply permissions to folder 'C:\Shared\BiscuitTin\Secure': Access is denied
05-05-2025 14:30:18 INFO: Applied permissions to file: C:\Shared\BiscuitTin\recipe_chocolate_chip.docx
05-05-2025 14:30:18 INFO: Applied permissions to file: C:\Shared\BiscuitTin\recipe_ginger_snap.pdf
05-05-2025 14:30:19 ERROR: Failed to apply permissions to file 'C:\Shared\BiscuitTin\Financial\secret_recipe.xlsx': The process cannot access the file because it is being used by another process.
05-05-2025 14:30:22 INFO: Processing complete. Successfully processed 56 items, 3 failures.
05-05-2025 14:30:22 INFO: Total items: 59
05-05-2025 14:30:22 INFO: Log file created at: C:\Logs\ApplySecurityGroup\ApplySecurityGroup_05-05-2025.log
05-05-2025 14:30:22 WARNING: Warning: Some items failed to process. Check the log for details.

Example Log File Output:

05-05-2025 14:30:15 INFO: Starting security group application process
05-05-2025 14:30:15 INFO: Target Folder: C:\Shared\BiscuitTin
05-05-2025 14:30:15 INFO: Security Group: KITCHEN\FS - RO - Shares - Biscuit Tin
05-05-2025 14:30:15 INFO: Permission: Read
05-05-2025 14:30:17 INFO: Found 12 folders and 47 files to process
05-05-2025 14:30:17 INFO: Applied permissions to folder: C:\Shared\BiscuitTin\Recipes
05-05-2025 14:30:17 INFO: Applied permissions to folder: C:\Shared\BiscuitTin\Financial
05-05-2025 14:30:18 WARNING: Failed to apply permissions to folder 'C:\Shared\BiscuitTin\Secure': Access is denied
05-05-2025 14:30:18 INFO: Applied permissions to file: C:\Shared\BiscuitTin\recipe_chocolate_chip.docx
05-05-2025 14:30:18 INFO: Applied permissions to file: C:\Shared\BiscuitTin\recipe_ginger_snap.pdf
05-05-2025 14:30:19 ERROR: Failed to apply permissions to file 'C:\Shared\BiscuitTin\Financial\secret_recipe.xlsx': The process cannot access the file because it is being used by another process.
05-05-2025 14:30:22 INFO: Processing complete. Successfully processed 56 items, 3 failures.
05-05-2025 14:30:22 INFO: Total items: 59
05-05-2025 14:30:22 INFO: Log file created at: C:\Logs\ApplySecurityGroup\ApplySecurityGroup_05-05-2025.log
05-05-2025 14:30:22 WARNING: Warning: Some items failed to process. Check the log for details.
Description
A powershell script which adds a security group to a folder and all subfiles and folders. To be used when subfolders have inheritance disabled but you still need to apply a security group to all.
Readme MIT 30 KiB
Languages
PowerShell 100%