The Windows Boot Feature Manager is a PowerShell script designed to enable or disable specific Windows features based on the currently selected boot entry. This tool simplifies the management of features for different boot configurations, ensuring that the right features are active for your selected environment.
- Requirements
- How to Create Boot Entry within Windows
- How the Code Works
- Using Task Scheduler
- Log File
- Usage
- Windows PowerShell
- Administrative privileges to run the script
- Windows 10 or later
To create a new boot entry, follow these steps:
- Open an elevated Command Prompt or PowerShell.
- Use the
bcdeditcommand to create a new entry. For example:bcdedit /copy {current} /d "$New_Boot_Entry" - This command copies the current boot entry and creates a new one with the specified name.
The script performs the following actions:
1.Check for Administrative Privileges:
The script checks if it is running with administrative rights. If not, it relaunches itself with elevated privileges.
#powershell
function Test-Admin { ... }2.Log File Initialization:
It initializes a log file to track the script's actions.
#powershell
Copy code
$logPath = "C:\Scripts\LogFile.log"3.Get the Current Boot Entry:
The script retrieves the currently selected boot entry from the boot manager.
#powershell
Copy code
foreach ($boot in $bootmanager) { ... }4.Enable or Disable Features:
Based on the current boot entry, the script enables or disables the feature.
#powershell
Copy code
if ($bootEntry -eq "$New_Boot_Entry") { ... }
elseif ($bootEntry -eq "$Current_Boot_Entry") { ... }To ensure that the script runs with the highest priority:
1.Open Task Scheduler. 2.Create a new task and set the following properties:
- Run with highest privileges.
- Trigger the task at system startup or on a specific event related to boot entries.
- Set the action to run your PowerShell script.
The script maintains a log file located at C:\Scripts\LogFile.log. This file records the actions taken by the script, including:
- Start and completion messages.
- Status of feature enabling or disabling.
- Any errors encountered during execution.
To use the Windows Boot Feature Manager:
1.Ensure the script is run with administrative privileges.
2.Execute the script in PowerShell:
#powershell
.\YourScriptName.ps1Upon execution, the log file will include entries such as:
#yaml
Copy code
2024-07-17 12:00:00 - Script started.
2024-07-17 12:00:01 - Current Boot Loaded : Windows Subsystem for Linux
2024-07-17 12:00:02 - Enabled feature: $feature_name
2024-07-17 12:00:03 - Script completed.