Add state and powershell script to enable Wake on Lan on Windows

This commit is contained in:
Adam Goldsmith 2022-10-05 14:25:36 -04:00
parent 46191399f4
commit 22b0204c7a
3 changed files with 43 additions and 0 deletions

37
enable-wakeonlan.ps1 Normal file
View File

@ -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)"

5
enable-wakeonlan.sls Normal file
View File

@ -0,0 +1,5 @@
Enable Wake-On-LAN:
cmd.script:
- name: salt://enable-wakeonlan.ps1
- shell: powershell
- stateful: True

View File

@ -16,5 +16,6 @@ base:
'G@os:Windows and classroomWin':
- fah
'G@os:Windows':
- enable-wakeonlan
- windowsWorkstation
- removeShortcuts