Trying to change brightness on my desktop screens via powershell and encountered an error

דרור פרוחי 5 Reputation points
2023-03-15T20:24:50.2633333+00:00

Hello,

I want to change the brightness of my screens (I have two screens) on my desktop computer using PowerShell. I use this command:

(Get-WmiObject -namespace root/wmi -class WmiMonitorBrightnessMethods).wmisetvrightness(1,20)

and I get an error :

Get-WmiObject : Not supported
At line:1 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 line:1 char:1
+ (Get-WmiObject -namespace root/wmi -class WmiMonitorBrightnessMethods ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

I use the same command on my laptop and it works.

I would like to know why I get this error and how to fix it.

I know that my computer does not programmatically support changing the brightness and I know that there are free third-party programs that perform this operation, yet I want to understand how they do it and what command those programs use.

I ask because I want to build software that reduces screen brightness.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,522 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,503 questions
{count} vote

3 answers

Sort by: Most helpful
  1. MotoX80 33,481 Reputation points
    2023-03-15T23:17:24.53+00:00

    If you have 2 monitors, then the WMI call is probably returning 2 objects.

    Try this.

    Get-WmiObject -namespace root/wmi -class WmiMonitorBrightnessMethods | foreach {
        $_.wmisetbrightness(80,20)
    }
    

  2. Castorix31 85,116 Reputation points
    2023-03-19T14:33:19.4933333+00:00

    I know that my computer does not programmatically support changing the brightness and I know that there are free third-party programs that perform this operation, yet I want to understand how they do it and what command those programs use.

    It can be done with GetVCPFeatureAndVCPFeatureReply / SetVCPFeature

    Brightness is 0x10 code (you can test codes with ClickMonitorDDC tool)

    0 comments No comments

  3. Rich Matheisen 46,711 Reputation points
    2023-03-22T15:09:33.29+00:00

    Are you running Windows Powershell 5, or the multi-platform PowerShell 7? WMI isn't part of PowerShell 7.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.