2

I type the command in Get Screen resolution using WMI/powershell in Windows 7, but I get empty result (I'm on Surface Pro 2017, single screen)?

enter image description here

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

4

I don't have a Surface, but does this work?

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
[pscustomobject]@{
    DeviceName   = $screen.DeviceName.Split('\\')[-1]
    Width        = $screen.Bounds.Width
    Height       = $screen.Bounds.Height
    BitsPerPixel = $screen.BitsPerPixel
}

EDIT

Using CIM_VideoController

$screen = Get-CimInstance -ClassName CIM_VideoController
[pscustomobject]@{
    DeviceName   = $screen.Caption
    Width        = $screen.CurrentHorizontalResolution
    Height       = $screen.CurrentVerticalResolution
    BitsPerPixel = $screen.CurrentBitsPerPixel
}
Theo
  • 57,719
  • 8
  • 24
  • 41
  • yes it works and I know it works but my question is about wmi ;) – user310291 Jul 21 '18 at 14:17
  • Apparently, starting with Windows Vista, hardware that is not compatible with Longhorn Display Driver Model (LDDM) returns inaccurate property values for instances of this class. Instead, you can use the `CIM_VideoController` object and get properties `CurrentHorizontalResolution`, `CurrentVerticalResolution` and `CurrentBitsPerPixel` from that (and more). Usage `Get-CimInstance -ClassName CIM_VideoController` – Theo Jul 21 '18 at 15:19
  • I'm on a Surface Pro 3 (Windows 10 Build 17713) and `Get-WmiObject -Class Win32_Desktopmonitor` correctly returns `ScreenWidth : 2160 ScreenHeight : 1440` – Jacob Jul 21 '18 at 17:38
  • @Jacob well that's ironic that old version of surface works ;) – user310291 Jul 23 '18 at 00:42
  • @Theo CIM_VideoController returns something : 2736 1824 which are maximum resolution I guess whereas my current resolution is set lower. But since that's also an interesting info, I'll check as good answer :) – user310291 Jul 23 '18 at 00:46