diff --git a/enable-wakeonlan.ps1 b/enable-wakeonlan.ps1 new file mode 100644 index 0000000..587a0e1 --- /dev/null +++ b/enable-wakeonlan.ps1 @@ -0,0 +1,37 @@ +# based on https://community.spiceworks.com/topic/2346039-help-with-windows-10-wake-on-lan-magic-packet-script + +$ErrorActionPreference = "Stop" + +$changes = @{} +foreach ($nic in Get-NetAdapter -Physical) { + $nicPowerWake = Get-WmiObject MSPower_DeviceWakeEnable -Namespace root\wmi | Where-Object {$_.InstanceName -match [regex]::escape($nic.PNPDeviceID) } + If ($nicPowerWake.Enable -ne $True) + { + $changes["$($nic.Name) MSPower_DeviceWakeEnable"] = $True + $nicPowerWake.Enable = $True + $nicPowerWake.psbase.Put() | Out-Null + } + + $nicMagicPacket = Get-WmiObject MSNdis_DeviceWakeOnMagicPacketOnly -Namespace root\wmi | Where-Object {$_.InstanceName -match [regex]::escape($nic.PNPDeviceID) } + If ($nicMagicPacket.EnableWakeOnMagicPacketOnly -ne $True) + { + $changes["$($nic.Name) EnableWakeOnMagicPacketOnly"] = $True + $nicMagicPacket.EnableWakeOnMagicPacketOnly = $True + $nicMagicPacket.psbase.Put() | Out-Null + } +} + +# TODO: None of the tested computers actually had this property +foreach ($eee in Get-NetAdapterAdvancedProperty | Where-Object DisplayName -eq "Energy-Efficient Ethernet") { + If ($eee.DisplayValue -eq "Enabled") { + $changes["Energy-Efficient Ethernet"] = $True + $eee | Set-NetAdapterAdvancedProperty -DisplayValue "Disabled" + } +} + +If ($changes.count -gt 0) { + $changes["comment"] = "Enabled $($changes.keys -join ', ')" + $changes["changed"] = $True +} + +write-host "$($changes | ConvertTo-Json -Compress)" diff --git a/enable-wakeonlan.sls b/enable-wakeonlan.sls new file mode 100644 index 0000000..70be472 --- /dev/null +++ b/enable-wakeonlan.sls @@ -0,0 +1,5 @@ +Enable Wake-On-LAN: + cmd.script: + - name: salt://enable-wakeonlan.ps1 + - shell: powershell + - stateful: True diff --git a/top.sls b/top.sls index c024ba8..d2f8a05 100644 --- a/top.sls +++ b/top.sls @@ -16,5 +16,6 @@ base: 'G@os:Windows and classroomWin': - fah 'G@os:Windows': + - enable-wakeonlan - windowsWorkstation - removeShortcuts