Skip to content

Instantly share code, notes, and snippets.

@sinkingsugar
Created April 25, 2025 01:52
Show Gist options
  • Save sinkingsugar/f6f39817b0b1623541db782386ae228b to your computer and use it in GitHub Desktop.
Save sinkingsugar/f6f39817b0b1623541db782386ae228b to your computer and use it in GitHub Desktop.
Clear ACPI
# Clear ACPI cache and force hardware rediscovery
# Run as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "Please run this script as Administrator!"
Exit
}
Write-Host "Clearing ACPI cache and forcing hardware rediscovery..." -ForegroundColor Green
# Stop Windows Management Instrumentation service
Stop-Service -Name Winmgmt -Force
# Clear WMI repository
Get-ChildItem -Path "$env:SystemRoot\System32\wbem\Repository" -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
# Clear device manager cache
Start-Process -FilePath "rundll32.exe" -ArgumentList "advapi32.dll,ProcessIdleTasks" -Wait
# Remove battery devices from registry
Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\ACPI\PNP0C0A*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Enum\ACPI\BAT*" -Recurse -Force -ErrorAction SilentlyContinue
# Restart Windows Management Instrumentation service
Start-Service -Name Winmgmt
# Scan for hardware changes
Start-Process -FilePath "rundll32.exe" -ArgumentList "setupapi.dll,CM_Run_Detection_Process" -Wait
# Force device manager to scan for new hardware
$process = Start-Process -FilePath "pnputil.exe" -ArgumentList "/scan-devices" -Wait -PassThru
Write-Host "Completed. Please restart your VM for changes to take full effect." -ForegroundColor Green
# Check for battery
Write-Host "\nChecking for battery after cleanup:" -ForegroundColor Cyan
Get-WmiObject -Class Win32_Battery | Format-List *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment