I'm working on a solution where machines are activated through Wake On Lan after which System Center pushes updates to the client pc's (running Windows 7).
Now I'm working at a script (PowerShell/C#), that checks if the machine should be shutdown after the updates finishes.
If the machine is activated through Wake On Lan and no user has logged on to the machine since activation, the machine can be safely closed. Otherwise, the machine should stay on.
Is there some way to check how the computer got activated?
Open the start menu and type "Device Manager" and open the device manager. Expand "Network Adapters" and right-click your network adapter (typically Intel) and select Properties. Click the "Power" or "Power Management" tab and make sure WOL is enabled.
Wake-on-LAN (WOL) allows a computer to be powered on or awakened from standby, hibernate or shutdown from another device on a network. The process of WOL is the following: The target computer is in standby, hibernate or shutdown, with power reserved for the network card.
Wake-on-LAN must be enabled in the desktop board BIOS and then configured in the operating system. To enable Wake-on-LAN in the BIOS: Press F2 during boot to enter BIOS Setup.
Since Windows 7 (maybe Vista), when you wakeup a computer "Microsoft-Windows-Power-Troubleshooter" provide a log in the System event log giving the wake up source. Here are two events (taken on Windows 8 desktop, but i've got the same ones on my Window 7 laptop), the first one was generated by a WOL, the second was generated using the front face button :
So using PowerShell you can test :
(Get-EventLog -LogName System -Source "Microsoft-Windows-Power-Troubleshooter" -AsBaseObject | Sort-Object {$_.timegenerated} | select -last 1 ).Message
This way you have to parse the message (not so good)
get-winevent -FilterHashtable @{"ProviderName"="Microsoft-Windows-Power-Troubleshooter";"id"=1} | Sort-Object {$_.timecreated} | select -last 1 | %{([xml]$_.ToXml()).Event.EventData.Data}
Remark : Microsoft-Windows-Power-Troubleshooter provider also exists on W2K8-R2, when I try to Wake On Lan one of my old server the WakeSourceType
is unknown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With