Are you running Windows Powershell 5, or the multi-platform PowerShell 7? WMI isn't part of PowerShell 7.
Trying to change brightness on my desktop screens via powershell and encountered an error
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
-
Castorix31 91,871 Reputation points2023-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)
-
MotoX80 37,686 Reputation points2023-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) }