Skip to content

Instantly share code, notes, and snippets.

@ra101
Last active March 8, 2022 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ra101/c2060ade52280b4fcbe3291331caf1e0 to your computer and use it in GitHub Desktop.
Save ra101/c2060ade52280b4fcbe3291331caf1e0 to your computer and use it in GitHub Desktop.
Script to control brightness via command
$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
@ra101
Copy link
Author

ra101 commented Jun 6, 2021

Article: dev.to

Commands:

.\brightness.ps1 <# No agrs will increase brightness #>
.\brightness.ps1 desc <# desc as arg will decrease brightness #>

@dchotwolf101
Copy link

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