By user281693

2011-11-01 14:08:30 8 Comments

I am using the following script to get screen resolution in Windows using WMI. The script works fine when the computer is in landscape mode but returns incorrect values when in portrait mode. Works properly in XP and did not try in Vista. Can anyone confirm this is bug in Windows 7 WMI.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_DesktopMonitor",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_DesktopMonitor instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "ScreenHeight: " & objItem.ScreenHeight
    Wscript.Echo "ScreenWidth: " & objItem.ScreenWidth


@Clayton 2016-08-02 21:09:11

@Shay Levy's answer above accurately reports the Width/Height that was active when the powershell session was launched. If you rotate monitor after PS launch, it continues to report the original, now incorrect values.

The SystemInformation class provides another way to get orientation, and it changes in the current PS session even if the display is rotated after the session launch.

Add-Type -AssemblyName System.Windows.Forms

IsEmpty                            Width                           Height
-------                            -----                           ------
False                              1680                             1050

Rotate monitor, then...


IsEmpty                            Width                           Height
-------                            -----                           ------
False                              1050                             1680

@Vlastimil Ovčáčík 2014-05-14 19:12:19

Same as the other answers, however for the plain cmd:

wmic path Win32_VideoController get VideoModeDescription

@Trevor Sullivan 2014-03-31 21:23:34

You can grab this from the Win32_VideoController WMI class. The VideoModeDescription property includes the screen resolution and the color depth.

(Get-WmiObject -Class Win32_VideoController).VideoModeDescription;


1600 x 900 x 4294967296 colors

@Shay Levy 2011-11-01 14:34:01

For the record, the PowerShell code is:

Get-WmiObject -Class Win32_DesktopMonitor | Select-Object ScreenWidth,ScreenHeight

I get the same values in Landscape or in Portrait mode.


In a multi monitor environment you can get the info for all monitors with:

PS> Add-Type -AssemblyName System.Windows.Forms
PS> [System.Windows.Forms.Screen]::AllScreens

BitsPerPixel : 32
Bounds       : {X=0,Y=0,Width=1280,Height=800}
DeviceName   : \\.\DISPLAY1
Primary      : True
WorkingArea  : {X=0,Y=0,Width=1280,Height=770}

BitsPerPixel : 32
Bounds       : {X=1280,Y=0,Width=1920,Height=1200}
DeviceName   : \\.\DISPLAY2
Primary      : False
WorkingArea  : {X=1280,Y=0,Width=1920,Height=1170}

@Kyle 2012-09-27 12:54:14

This seems to only find the first monitor. Is there a way to get the resolution for all of the monitors?

@Clayton 2016-08-02 21:05:16

The second method here accurately reports the Width Height that was active when the powershell session was launched. If you rotate monitor after PS launch, it continues to report the original, now incorrect values. See answer below for another method that works in the same PS session even after monitor is rotated.

@KnorxThieus 2017-06-20 18:43:03

Very nice solution, regarding to the update (WMI solution does not work for me, Win 10). Unfortunately, you have to multiply width and height of the bound objects by dpi scaling factor (to configure in Windows Settings > System > Display), e. g. by 1.25 for 125%.

@Andrei Krasutski 2019-11-12 21:00:27

The first method returned empty in ScreenWidth and ScreenHeight. The second method perfect

@S0me0ne 2012-05-09 16:32:58

You can get all available resolution with this command:

$Query = "SELECT * FROM CIM_VideoControllerResolution"
$res = Get-WMIObject -query $Query | Select Caption

Related Questions

Sponsored Content

30 Answered Questions

[SOLVED] PowerShell says "execution of scripts is disabled on this system."

7 Answered Questions

[SOLVED] How do you comment out code in PowerShell?

16 Answered Questions

[SOLVED] Setting Windows PowerShell environment variables

  • 2009-04-03 17:19:35
  • Vasil
  • 623313 View
  • 603 Score
  • 16 Answer
  • Tags:   windows powershell

18 Answered Questions

[SOLVED] Determine installed PowerShell version

  • 2009-12-01 11:30:03
  • MagicAndi
  • 2946067 View
  • 2632 Score
  • 18 Answer
  • Tags:   powershell

2 Answered Questions

[SOLVED] Using variables in vbs WMI methods

3 Answered Questions

[SOLVED] Use WMI to get current Windows username in VBA

1 Answered Questions

WMI Get Object Access Denied

1 Answered Questions

[SOLVED] Unable to obtain physical memory informatin using powershell

Sponsored Content