-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows-screen-suspender.ps1
25 lines (19 loc) · 1.17 KB
/
windows-screen-suspender.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$objWMi1 = get-wmiobject -namespace root\WMI -computername localhost -Query "Select * from WmiMonitorConnectionParams"
function Set-Lid-Configuration {
if ($objWMi1.Count -lt 2) { # Without external monitors
powercfg -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
powercfg -setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 1
} else { # With external monitors
powercfg -setacvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
powercfg -setdcvalueindex 381b4222-f694-41f0-9685-ff5bb260df2e 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0
}
}
Set-Lid-Configuration # Initial configuration
while($true) {
Start-Sleep -s 5
$objWMi2 = get-wmiobject -namespace root\WMI -computername localhost -Query "Select * from WmiMonitorConnectionParams"
if ($objWMi1.Count -ne $objWMi2.Count) {
$objWMi1 = $objWMi2
Set-Lid-Configuration
}
}