After we push out updates to Windows desktops we will inevitably end up with some that will no longer go to sleep. Occasionally they will sleep but their monitors won’t turn off. When this happens to one or two systems it’s an annoyance. If it happens to a lot of them, there can be a financial impact due to the extra power consumption.

Generally, the problem is caused by an incompatibility between one of the newly installed updates and a system driver. Sometimes it’s caused by the update itself. How are you supposed to figure out exactly what is causing the problem?

Microsoft has embedded a utility named “powercfg” in the operating system. This tool can diagnose and assist in the repair of most power related problems. The first step is to run a diagnostics report. You can do this from a command prompt on a single computer but you should be getting used to PowerShell by now and if you’ve got lots of systems you need to check, it will be your best bet anyway.

Open an elevated PowerShell console, the command is;

PowerCfg /SystemSleepDiagnostics /Output $env:userprofile\Documents\sleep-diagnostics-report.html

The command will create a nicely formatted report in your documents folder showing all the information you should need to determine the cause. Scroll through the user sessions and expand the Red menus to see the cause of your issue.

PowerReport_Red

Below, you can see that in my case, OVRServer_x64.exe continued to request power after the system had tried to sleep. As you can probably tell from the file path, that EXE file is part of the Oculus Rift software package. Again, you can click the Red bar to gain more information.

PowerReport_Error

Now that we know what’s causing the problem there are several things we can try to correct it. First, I always check to see if there’s an update for the application or driver. For many programs, in the help menu you’ll find a “Check for updates” option. If you need to visit the software or hardware vendor’s web site, updates are usually found under the “Support” section.

What if there is no update? Are you just out of luck? There are still options available that we need to investigate before giving up. PowerCfg can be used to override power requests from mis-behaving apps and drivers. The command differs depending on what’s causing the problem. Let’s check help to see what our options are.

PowerCfg_OverRide_Help

Looks easy enough, to create an override for my trouble maker the command would be;

PowerCfg /RequestsOverRide PROCESS OVRServer_x64.exe DISPLAY

As the help suggests, to figure out the name and type of your issue you can run “PowerCfg /Requests”  After creating the override you’ll need to wait for the sleep interval to occur to know if it worked or not. Most of the time it will.

If the override doesn’t solve your problem you are left with rolling back the update. You can either uninstall the update or use a system restore point. I also recommend waiting a few days and checking for updates from both Microsoft and the vendor again. Many times, once they become aware of the issue one of them will release a patch for the problem.

So how do we apply what we’ve learned to a lot of systems? We use a PowerShell script of course. Since PowerCfg is an exe embedded on each computer we’ll use invoke-command to activate it in a foreach loop. You’ll probably want to redirect the reports to a network share rather than connecting to each system to view them. That will mean naming the reports in a way that tells you where they came from.

Import-Module ActiveDirectory
$domains=(Get-ADForest).domains

$dcs = foreach ($domain in $domains) {Get-ADDomainController -DomainName $domain -Discover -Service PrimaryDC|select -ExpandProperty hostname}

$systems = foreach ($dc in $dcs) {
Get-ADComputer -properties * -Filter {(OperatingSystem -like "*Windows*") -and (OperatingSystem -NotLike "*Server*")} -Server $domain |select DNSHostName -ExpandProperty DNSHostName}

Foreach ($system in $systems) {
Invoke-Command -ComputerName $system -ScriptBlock {PowerCfg /SystemSleepDiagnostics /Output \\report_share\$system+sleep-diagnostics-report.html}}

The script above will generate the sleep diagnostics report for every workstation computer on your network and store the report in the share you specify with the computer’s name in appended to the report. The same invoke-command technique would let you create an override for each computer that has an issue.

Advertisements