I know it sounds a bit out there, but I'm trying to figure out if there's a way to determine whether a remote computer is currently in sleep mode. I've noticed that with Windows Modern Standby, even if the network is disconnected, it seems to respond to some remote PowerShell commands, which messes up my scripts. Is there a way to monitor the sleep state of a remote machine or check how long it's been idle?
5 Answers
Using a syslog server could work too. If clients log their power state, you can fetch those logs to see if they’re asleep. It’s a bit heavier than other methods but it can definitely get the job done.
You can check the event logs since they record when a computer goes to sleep and when it wakes up. If you configure it correctly, some network traffic can wake the machine. What specifically are you trying to accomplish with this?
I’m not sure you can actually get the sleep state of a remote system. However, I do have a function that checks the last reboot time and calculates the uptime from there. It’s not perfect but gives you some insight.
To really monitor the sleep state, you'd likely need an agent running on the remote machine that can report changes back to you. There’s a Win32 API 'getLastInputInfo' that can help with idle time detection, but you might have to check all users and RDP sessions as well.
Using Ivanti Endpoint Manager might be your best bet. It can display vital information about remote machines, including their sleep status. Plus, it has the capability to wake devices for updates or script execution, then put them back to sleep afterwards.
I find waking up wireless computers can be hit or miss, though. Wake-on-LAN doesn’t always work reliably.
Hmm, good point! If I can query the event logs for the last sleep or wake event, I should be able to tell if the machine is sleeping. I'll try that, thanks!