I am trying to create a worklet that will enable Wake-on-LAN on every network adapter on Windows 11. Here is the script.
# 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.
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.