DEV Community

Kamran Liaquat Ali
Kamran Liaquat Ali

Posted on

powercfg in PowerShell vs CMD: 5 Gotchas That Break the Windows Battery Report

Windows has a built-in battery report that shows how much capacity a laptop battery has lost. Generating it is one command:

powercfg /batteryreport
Enter fullscreen mode Exit fullscreen mode

It looks trivial, yet it fails surprisingly often. While building a small browser tool that reads these reports, I kept seeing the same handful of failures in search queries and support threads. Almost all of them come down to one thing: the same command line means different things in PowerShell and in Command Prompt.

Here are the five gotchas worth knowing.

1. A missing space becomes an unknown command in PowerShell

PS> powercfg/batteryreport
powercfg/batteryreport : The term 'powercfg/batteryreport' is not recognized as the name of a cmdlet, function, script file, or operable program.
Enter fullscreen mode Exit fullscreen mode

PowerShell tokenises powercfg/batteryreport as a single command name and tries to resolve it as a cmdlet, function or executable. Nothing by that name exists, so it fails. Always keep the space:

powercfg /batteryreport
Enter fullscreen mode Exit fullscreen mode

2. %USERPROFILE% is not expanded in PowerShell

Most tutorials show this to save the report on the desktop:

powercfg /batteryreport /output "%USERPROFILE%\Desktop\battery-report.html"
Enter fullscreen mode Exit fullscreen mode

That is Command Prompt syntax. In PowerShell, %USERPROFILE% is just literal text, so powercfg receives a path that does not exist. Use PowerShell's environment provider instead:

powercfg /batteryreport /output "$env:USERPROFILE\Desktop\battery-report.html"
Enter fullscreen mode Exit fullscreen mode

3. Or tell PowerShell to stop parsing with --%

If you want to paste a CMD-style line into PowerShell unchanged, use the stop-parsing token:

powercfg --% /batteryreport /output "%USERPROFILE%\Desktop\battery-report.html"
Enter fullscreen mode Exit fullscreen mode

After --%, PowerShell passes the rest of the line through literally. According to Microsoft's about_Parsing documentation, the only interpretation it still performs is expanding Windows-style %variable% environment variables, which is exactly what this command needs. The effect lasts until the end of the line.

4. "Saved to C:\WINDOWS\system32" surprises people

Run the command in an elevated window and you will often see:

Battery life report saved to file path C:\WINDOWS\system32\battery-report.html.
Enter fullscreen mode Exit fullscreen mode

Administrator shells usually start in C:\WINDOWS\system32, and without /output the report is written to the current directory. The file is there, just not where people look. Either pass /output, or open it straight away:

# PowerShell
Invoke-Item .\battery-report.html
Enter fullscreen mode Exit fullscreen mode
:: Command Prompt
start battery-report.html
Enter fullscreen mode Exit fullscreen mode

5. Copy-paste brings invisible problems

Commands copied from web pages and chat apps sometimes carry smart quotes (“ ”) or a dash that is not a real ASCII hyphen. powercfg then reports invalid parameters even though the line looks correct. When a command that "should work" fails, retype it by hand.

Bonus: error 0x422

Unable to perform operation. An unexpected error (0x422) has occurred:
The service cannot be started, either because it is disabled or because
it has no enabled devices associated with it.
Enter fullscreen mode Exit fullscreen mode

0x422 is ERROR_SERVICE_DISABLED. A service the report relies on has been switched off, often by a "debloat" or tweak tool. A commonly reported fix is to re-enable Diagnostic Policy Service (services.msc, Startup type: Automatic) and restarting fixes it; if a tweak tool was used, reverting its service changes is the cleaner fix.

Quick reference

Task Command Prompt PowerShell
Generate report powercfg /batteryreport powercfg /batteryreport
Save to desktop /output "%USERPROFILE%\Desktop\battery-report.html" /output "$env:USERPROFILE\Desktop\battery-report.html"
Paste CMD syntax as-is n/a powercfg --% ...
Open the file start battery-report.html Invoke-Item .\battery-report.html

I wrote up the full step-by-step for users still on Windows 10, where the Win + X menu opens PowerShell by default, here: How to get a battery report in Windows 10. If you have hit a powercfg error that is not on this list, I would like to hear about it in the comments.

Top comments (0)