Check if your computer is activated through Wake On Lan

I am working on a solution in which machines are activated through Wake On Lan, after which System Center pushes updates to the client PC (runs on Windows 7).

Now I am working on a script (PowerShell / C #) that checks if the machine should shut down after the updates are completed.

If the machine is activated through Wake On Lan, and after activation the user is not logged in, the machine can be safely closed. Otherwise, the machine must remain in place.

Is there a way to check how the computer is activated?

+7
c # powershell wake-on-lan
source share
2 answers

Starting with Windows 7 (possibly Vista), when you start the Microsoft-Windows-Power-Troubleshooter computer, you can enter the system event log by specifying the source of the wake-up. Here are two events (taken on the Windows 8 desktop, but I have the same on my Window 7 laptop), the first was generated by WOL, the second was generated using the button on the front panel:

enter image description hereenter image description here

So, using PowerShell, you can test:

(Get-EventLog -LogName System -Source "Microsoft-Windows-Power-Troubleshooter" -AsBaseObject | Sort-Object {$_.timegenerated} | select -last 1 ).Message 

So you need to parse the message (not very good)

 get-winevent -FilterHashtable @{"ProviderName"="Microsoft-Windows-Power-Troubleshooter";"id"=1} | Sort-Object {$_.timecreated} | select -last 1 | %{([xml]$_.ToXml()).Event.EventData.Data} 

Note. The Microsoft-Windows-Power-Troubleshooter provider also exists on W2K8-R2, when I try to run Wake On Lan on one of my old servers, WakeSourceType unknown.

+1
source share

This may not be exactly what you are looking for, but an alternative approach:

  • On the server side, remember when the WOL packet was sent
  • On the client side, ask the server about the last time the WOL package was
  • On the client side, check the health of the PC, for example. using WMI for Powershell uptime or Codeplex Endpoint
  • Compare two. Perhaps we will consider some delays for the equipment loading process. I don’t know for sure whether uptime is considered hardware or software.
  • For registered users, you can use WMI to log in from Powershell
0
source share

All Articles