I wanted a script to ensure the three options in the screen grab below are enabled. PowerShell is my preferred scripting solution, and this customer also wants as much scripting done in PowerShell as possible. I found a number of VBScripts examples that I then used to construct my PowerShell script, so I don't take credit for the logic here but I couldn't find a complete PowerShell solution so I hope this is useful for someone. I'm no PowerShell guru, so if anyone sees ways to improve this script - please feel free to share ideas.
Anyway, here is the screen grab showing the settings I wanted to set:
Here are some links to where I got my logic and ideas from:
ConfigMgr 2007: Implementing Wake-on-LAN (WoL): This article explains setting up WOL with ConfigMgr very well and includes a VBScript that was my main source for understanding what WMI exposed that I could use for my script
Configure a Network Adapter to Wake a Computer Via PowerShell: This article was where I found the base I used for my script in PowerShell, it shows how to get at one of the properties via WMI, after figuring this out the rest of the script was easy.
My script follows below. One thing I've added that is different from the two great articles above is that I look only for physical ethernet adaptors. I don't try to configure these settings on virtual adaptors or wireless adaptors (others might want to do this for wireless adaptors, Windows 7 does support WOL over wireless, but that isn't a requirement for my customer). Eliminating virtual adaptors from being configured stops the script touching the various virtual adaptors that various remote access solutions like to add to Windows.
#
#
# Purpose: Enables Wake on LAN (WOL) settings on active wired network cards
#
# Usage : powershell.exe -f .\EnableWOL.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 18/06/12 Script Created justanothertechnicalblog
#
#
$nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' AND PhysicalAdapter = 'true'"
foreach ($nic in $nics)
{
$nicName = $nic.Name
Write-Host "--- Enable `"Allow the computer to turn off this device to save power`" on $nicName ---"
$nicPower = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPower.Enable = $True
$nicPower.psbase.Put()
Write-Host "--- Enable `"Allow this device to wake the computer`" on $nicName ---"
$nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPowerWake.Enable = $True
$nicPowerWake.psbase.Put()
Write-Host "--- Enable `"Only allow a magic packet to wake the computer`" on $nicName ---"
$nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicMagicPacket.EnableWakeOnMagicPacketOnly = $True
$nicMagicPacket.psbase.Put()
}
UPDATE 19 June 2012:
Testing today on a laptop I found the above script will identify the inbuilt Intel Centrino Ultimate-N 6300 AGN on a Dell Latitude E6510 as an Ethernet adaptor when it plainly isn't. It then fails to set some of the properties above as they are not supported. Not a big deal, the inbuilt Ethernet adaptor is treated correctly so the result is successful, but messy. I might have to use the 'netenabled' filter used in the PowerShell Guys' posting above.
UPDATE 06 July 2012:
Here is my updated script to exclude wireless and other cards:
# ----------------------------------------------------------------------
#
# Purpose: Enables Wake on LAN (WOL) settings on active wired network cards
#
# Usage : powershell.exe -f .\EnableWOL.ps1
#
# Version 1.0
#
# Maintenance History
# ----------------------------------------------------------------------
# Version - Date - Change - Author
# ----------------------------------------------------------------------
# 1.0 18/06/12 Script Created justanothertechnicalblog
# 2.0 04/07/12 Updated to exclude justanothertechnicalblog
# Wireless/WiFi/Bluetooth
# Get all physical ethernet adaptors
$nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' `
AND PhysicalAdapter = 'true' `
AND NOT Description LIKE '%Centrino%' `
AND NOT Description LIKE '%wireless%' `
AND NOT Description LIKE '%WiFi%' `
AND NOT Description LIKE '%Bluetooth%'"
foreach ($nic in $nics)
{
$nicName = $nic.Name
Write-Host "--- Enable `"Allow the computer to turn off this device to save power`" on $nicName ---"
$nicPower = Get-WmiObject MSPower_DeviceEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPower.Enable = $True
$nicPower.psbase.Put()
Write-Host "--- Enable `"Allow this device to wake the computer`" on $nicName ---"
$nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicPowerWake.Enable = $True
$nicPowerWake.psbase.Put()
Write-Host "--- Enable `"Only allow a magic packet to wake the computer`" on $nicName ---"
$nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | where {$_.instancename -match [regex]::escape($nic.PNPDeviceID) }
$nicMagicPacket.EnableWakeOnMagicPacketOnly = $True
$nicMagicPacket.psbase.Put()
}
