Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2019 03:42
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
function Set-WakeEnabled
Set WoL on nic
Author: Jan-Henrik Damaschke (@jandamaschke)
License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None
Set Wake on Lan (WOL) settings for specific network interface card
.PARAMETER InterfaceName
Specifies the name of the interface where WoL setting should be changed
.PARAMETER WakeEnabled
Specifies if WoL should be enabled or disabled
PS C:\> Set-WakeEnabled -InterfaceName Ethernet -WakeEnabled $true
[CmdletBinding()] Param(
[Parameter(Mandatory = $True, ParameterSetName="InterfaceName")]
[Parameter(Mandatory = $True)]
[Parameter(Mandatory = $True, ParameterSetName="ConnectionID")]
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
$nicsWakeEnabled = Get-CimInstance -ClassName MSPower_DeviceWakeEnable -Namespace root/wmi
$nics = Get-CimInstance -ClassName Win32_NetworkAdapter | Where-Object NetEnabled -eq $true
if ($InterfaceName){
$nic = $nics | Where-Object Name -eq $InterfaceName
else {
$nic = $nics | Where-Object NetConnectionID -eq $NetConnectionID
$nicWakeEnabled = $nicsWakeEnabled | Where-Object InstanceName -like "*$($nic.PNPDeviceID)*"
$enabled = $nicWakeEnabled.Enable
if (!($enabled -and $WakeEnabled)){
Set-CimInstance $nicWakeEnabled -Property @{Enable=$enabled}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment