Files
management-scripts/Fix-RebootIntoSafeMode.ps1
T

32 lines
1.6 KiB
PowerShell
Raw Normal View History

2024-04-22 11:31:28 -04:00
# List of services to configure
$Services = @(
2024-04-22 15:46:26 -04:00
"Syncro",
"SyncroLive",
"SyncroOvermind",
2024-04-22 11:31:28 -04:00
"SplashtopRemoteService"
)
# Configure necessary services to restart in Safe Mode with Networking
$Services | ForEach-Object {
If ( Get-Service $_ -ErrorAction SilentlyContinue ) {
Write-Output "Configuring ${_} service to start in Safe Mode with Networking"
2024-04-22 15:46:26 -04:00
Try { New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\${_}" -Force -ErrorAction SilentlyContinue | Out-Null }
2024-04-22 11:31:28 -04:00
Catch { Write-Error "ERROR: could not configure ${_} service to start in Safe Mode with Networking" ; Return }
}
}
# Configure system to reboot into Normal Mode at next reboot
Write-Output "Configuring system to reboot into Normal Mode at next reboot"
2024-04-22 15:46:26 -04:00
Try { [Microsoft.Win32.Registry]::SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce",'*RestartNormalMode','cmd.exe /c "%SystemRoot%\System32\bcdedit.exe" /deletevalue {default} safeboot',[Microsoft.Win32.RegistryValueKind]::String) }
2024-04-22 11:31:28 -04:00
Catch { Write-Error "ERROR: could not configure reboot into normal mode" ; Return }
# Configure reboot into Safe Mode with Networking
Write-Output "Configuring system to reboot into Safe Mode with Networking"
2024-04-22 12:44:11 -04:00
$command = "${Env:SystemRoot}\System32\bcdedit.exe"
$params = "/set {default} safeboot network".Split(" ")
Try { & "${command}" $params }
2024-04-22 11:31:28 -04:00
Catch { Write-Error "ERROR: could not configure reboot into safe mode with networking" ; Return }
# Reboot into Safe Mode with Networking
Write-Output "Rebooting into Safe Mode with Networking"
2024-04-22 12:48:40 -04:00
& "${Env:SystemRoot}\System32\shutdown.exe" -r -f -t 5