Share via

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 for business | Windows Server | User experience | PowerShell

3 answers

Sort by: Most helpful
  1. Rich Matheisen 48,116 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.

    Was this answer helpful?

    0 comments No comments

  2. Castorix31 91,871 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)

    Was this answer helpful?

    0 comments No comments

  3. MotoX80 37,686 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)
    }
    

    Was this answer helpful?


Your answer

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