A set of PowerShell scripts designed to facilitate the management, permission changes, and deletion of Windows Component Based Servicing (CBS) registry keys. The tool consists of two main scripts:
- Main.ps1: Acts as the entry point, handling user input and orchestrating the workflow.
- Task_Scheduled_Script.ps1: Contains the core logic for directory creation, logging, permission changes, and registry key deletions.
- Logging: Logs every step and action to a file for traceability.
- Scheduled Task Creation: Automates the execution of tasks via the Windows Task Scheduler.
- Registry Key Management: Handles permission changes and ownership updates for registry keys.
- Safe Cleanup: Removes temporary files and resets scripts for future use.
- Modularity: Split into two scripts for better organization and reusability.
- PowerShell: Requires PowerShell 5.1 or later.
- Administrator Privileges: The script must be run as an administrator.
- Windows Task Scheduler: Necessary for automating script execution.
-
Prepare the Scripts:
- Place
Main.ps1
andTask_Scheduled_Script.ps1
in the same directory. - Ensure the paths in the scripts (e.g.,
C:\temp
) are accessible.
- Place
-
Run the Main Script:
- Open PowerShell as an administrator.
- Navigate to the directory containing
Main.ps1
. - Execute the script:
.\Main.ps1
-
Follow Prompts:
- Enter the KB number when prompted (e.g.,
KB450765
). - The script will handle the rest, including creating scheduled tasks, monitoring execution, and cleaning up after completion.
- Enter the KB number when prompted (e.g.,
The entry point script. It handles user input, sets up the scheduled task, monitors its execution, and performs cleanup.
-
Set-Logging
: Logs actions and outputs them to the console. -
Create_ScheduledTask
: Checks for and creates a scheduled task to execute the secondary script. -
Start_ScheduledTask
: Starts the scheduled task. -
Task_Scheduled_Status
: Monitors the status of the scheduled task until completion. -
Refresh_ScheduledTask_Script
: Resets the placeholder in the secondary script for reuse. -
Remove_ScheduledTask
: Deletes the created scheduled task after use.
The core logic script. Handles logging, directory creation, permission changes, and registry key deletions.
-
Create_Directory
: Ensures the existence of theC:\temp
directory. -
Set-Logging
: Logs actions to the fileC:\temp\Package_Deletion.log
. -
Change_Control
: Modifies permissions for a registry key and itsOwners
subkey. -
Remove_Packages
: Deletes specified registry keys and logs the operation. -
Change_Ownership
: Changes the ownership of registry keys, updates permissions, and deletes them.
-
Administrative Access: The script requires elevated privileges to modify registry keys.
-
Irreversible Actions: Once registry keys are deleted, they cannot be recovered unless previously backed up.
-
Intended Use: This tool should be used with caution and only when necessary. Ensure proper backups are taken before proceeding.
Requesting User input.
Please enter the full KB number, for example, KB450765: KB500765
Creating Scheduled Task.
Scheduled Task started.
Waiting for Scheduled task to complete...
Scheduled Task completed.
Refreshing Scheduled Task script for next use.
Scheduled task removed.
Temp Directory 'C:\temp' exists.
Changing permissions to Full Control for the SYSTEM profile for PackageName.
PackageName permissions updated.
Removing PackageName.
PackageName has been removed.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! If you encounter issues or have suggestions for improvements:
- Fork the repository.
- Create a new branch (
feature/your-feature-name
). - Commit your changes (
git commit -m 'Add your feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - Open a pull request.
Happy scripting! 🚀