Add state and powershell script to enable Wake on Lan on Windows
This commit is contained in:
parent
46191399f4
commit
22b0204c7a
37
enable-wakeonlan.ps1
Normal file
37
enable-wakeonlan.ps1
Normal 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
5
enable-wakeonlan.sls
Normal file
@ -0,0 +1,5 @@
|
||||
Enable Wake-On-LAN:
|
||||
cmd.script:
|
||||
- name: salt://enable-wakeonlan.ps1
|
||||
- shell: powershell
|
||||
- stateful: True
|
Loading…
Reference in New Issue
Block a user