AutomoxAutomox

Worklet - Enable Wake-on-LAN

slammert
January 16, 2025 at 2:59 pm UTC

I am trying to create a worklet that will enable  Wake-on-LAN on every network adapter on Windows 11.  Here is the script.

powershell29 lines
# Enable Wake-on-LAN on all network interfaces

# Function to enable WoL
Function Enable-WakeOnLAN {
    # Get all network adapters
    $adapters = Get-NetAdapter -Physical | Where-Object { $_.Status -eq "Up" }

    foreach ($adapter in $adapters) {
        Write-Host "Configuring adapter: $($adapter.Name)" -ForegroundColor Green

        try {
            # Enable "Wake on Magic Packet"
            Set-NetAdapterAdvancedProperty -Name $adapter.Name -RegistryKeyword "WakeOnMagicPacket" -RegistryValue 1 -ErrorAction Stop

            # Enable "Wake on Pattern Match" (optional, depending on requirements)
            Set-NetAdapterAdvancedProperty -Name $adapter.Name -RegistryKeyword "WakeOnPattern" -RegistryValue 1 -ErrorAction Stop

            # Ensure the "Shutdown Wake-On-Lan" setting is enabled
            Set-NetAdapterPowerManagement -Name $adapter.Name -AllowWakeArmed $true -WakeOnMagicPacket $true -ErrorAction Stop

            Write-Host "Wake-on-LAN enabled for adapter: $($adapter.Name)" -ForegroundColor Cyan
        } catch {
            Write-Host "Failed to configure adapter: $($adapter.Name). Error: $_" -ForegroundColor Red
        }
    }
}

# Run the function
Enable-WakeOnLAN

It is failing with this message.

2 lines
Configuring adapter: Ethernet
Failed to configure adapter: Ethernet. Error: No matching MSFT_NetAdapterAdvancedPropertySettingData objects found by CIM query for instances of the ROOT/StandardCimv2/MSFT_NetAdapterAdvancedPropertySettingData class on the  CIM server: SELECT * FROM MSFT_NetAdapterAdvancedPropertySettingData  WHERE ((Name LIKE 'Ethernet')) AND ((RegistryKeyword = 'WakeOnMagicPacket')). Verify query parameters and retry.

 

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (2)

JohnG-AutomoxJanuary 28, 2025
#1

Hi ​@slammert !

I've used WoL before with some success directly through Powershell PsSessions. Passing a Magic Packet to a disconnected device via a Worklet however won’t be possible since the Automox agent would need to be a connected state first and able to receive commands before it can run any Worklet code.

There might be some workarounds like issuing the Worklet to an online jump box on the same network, that device sends the WoL package via a PSsession, but I haven't tried this though!

While this doesn’t solve for your immediate need, I opened a feature request on your behalf for Wake On Lan capabilities with our Product team.

If you could share some use cases on why Wake On Lan would be beneficial to you and your team, please do share and I’ll get those added to the feature request.


Thanks and have a great day!

slammertJanuary 28, 2025
#2

Thanks for the insight John.