Batch File - Delete All Power Plans w/ PowerCfg

Status
Not open for further replies.

eperezjr

Distinguished
Nov 18, 2011
3
0
18,510
Can someone assist me in completing this task?

I have an application that imports a custom power plan and then deletes it and adds the old one back one when the application closes. But as I've been debugging, I'll end the debugging and the closing event won't fire. So the power plans never delete when I do that.

Right now, there's hundreds of power plans and I'm deleting them manually. Since you need a GUID to delete them through the command prompt, I was hoping someone could help me enumerate through the GUIDs and delete them.

Thanks
 
Solution
Don't have a Windows System to write this for you right now I'm afraid but take a look at this for a starter on how to iterate through the result of powercfg -list.

I wouldn't run this code verbatim because I have no idea what the results for powercfg -list looks like but you want to do something like:

[cpp]
for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
powercfg -delete %%G
)
[/cpp]

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060
Don't have a Windows System to write this for you right now I'm afraid but take a look at this for a starter on how to iterate through the result of powercfg -list.

I wouldn't run this code verbatim because I have no idea what the results for powercfg -list looks like but you want to do something like:

[cpp]
for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
powercfg -delete %%G
)
[/cpp]
 
Solution

eperezjr

Distinguished
Nov 18, 2011
3
0
18,510


You, sir, are amazing. Although you warned not running it as is, I went ahead and did so. It worked perfectly.

Thanks again, my friend!
 
Status
Not open for further replies.