Skip to content

Scripts Windows SafeMode

Quadstronaut edited this page Jun 7, 2026 · 1 revision

Scripts: Safe Mode

Scripts in Scripts/Windows/SafeMode/. Both require administrator privileges.

Safe Mode with Networking loads a minimal driver set plus network drivers. It is useful for:

  • Malware removal (malware often cannot run without its normal startup context)
  • Driver troubleshooting (a bad driver causing a blue screen won't load in Safe Mode)
  • Remote diagnostics (network is available unlike plain Safe Mode)

Enter-SafeMode.ps1

What it does: Sets the bcdedit safeboot flag to network and immediately reboots the machine into Safe Mode with Networking.

Parameters: None.

Requirements: Administrator privileges. Will reboot immediately.

Usage:

.\Scripts\Windows\SafeMode\Enter-SafeMode.ps1

How it works:

bcdedit.exe /set '{current}' safeboot network
Restart-Computer -Force

Important: Save all work before running this. The reboot is immediate and forced — there is no confirmation prompt.

To undo before rebooting: If you set this flag by mistake and haven't rebooted yet, run Exit-SafeMode.ps1 to clear it before the restart.


Exit-SafeMode.ps1

What it does: Removes the bcdedit safeboot flag so the machine boots normally on the next restart. Does not reboot.

Parameters: None.

Requirements: Administrator privileges.

Usage:

.\Scripts\Windows\SafeMode\Exit-SafeMode.ps1

How it works:

bcdedit /deletevalue '{current}' safeboot

Run this while in Safe Mode, then restart manually when ready. Or run it before a scheduled reboot if you accidentally set the Safe Mode flag.


Workflow: Enter and Exit Safe Mode

# Step 1: Enter Safe Mode (reboots immediately)
.\Scripts\Windows\SafeMode\Enter-SafeMode.ps1

# --- machine reboots into Safe Mode ---

# Step 2: Do your troubleshooting work

# Step 3: Clear the flag while still in Safe Mode
.\Scripts\Windows\SafeMode\Exit-SafeMode.ps1

# Step 4: Restart to return to normal boot
Restart-Computer

Troubleshooting

"This script needs to be run as an administrator." Right-click your PowerShell shortcut → "Run as administrator", then run the script.

bcdedit fails with "Access denied" You are not running as administrator. The script checks and exits rather than auto-elevating. See above.

Machine stuck in Safe Mode after Enter-SafeMode.ps1 If the machine always reboots into Safe Mode, boot into Safe Mode and run Exit-SafeMode.ps1, then reboot normally.

If you cannot boot at all, use Windows Recovery Environment (WinRE):

  1. Boot from Windows installation media.
  2. Choose "Repair your computer" → Troubleshoot → Advanced options → Command Prompt.
  3. Run: bcdedit /deletevalue {default} safeboot
  4. Restart.

Clone this wiki locally