Last active
March 8, 2022 21:16
-
-
Save ra101/c2060ade52280b4fcbe3291331caf1e0 to your computer and use it in GitHub Desktop.
Script to control brightness via command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$brightness = (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightness).CurrentBrightness | |
if ($args[0] -eq "desc") { | |
$brightness = (([int]($brightness / 10) * 10 - 10), 0 | Measure -Max).Maximum | |
} | |
else { | |
$brightness = (([int]($brightness / 10) * 10 + 10), 100 | Measure -Min).Minimum | |
} | |
(Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, $brightness) | |
exit |
This is all that I get when I run the code.
Get-WmiObject : Not supported
At C:\users\dbuch\desktop\brightness.ps1:1 char:16
- ... ightness = (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBright ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
- FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Get-WmiObject : Not supported
At C:\users\dbuch\desktop\brightness.ps1:10 char:2
- (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods ...
-
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
You cannot call a method on a null-valued expression.
At C:\users\dbuch\desktop\brightness.ps1:10 char:1
- (Get-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods ...
-
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Article: dev.to
Commands:
.\brightness.ps1 <# No agrs will increase brightness #>
.\brightness.ps1 desc <# desc as arg will decrease brightness #>