We are preparing to deploy a new large information system. before we roll it out, I have been asked to gather an inventory that includes Monitor size. I can’t find “Monitor Size” (they want it in Inches) but I have found a WMI query to let me gather the Screen Width and Height.
if (exists wmi) then (string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) else (“N/A”)
if (exists wmi) then (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi) else (“N/A”)
What I would LIKE to do is gather this into a Retrieved Property listing WidthxHeight, but I have not been able to figure it out yet. Each attempt comes back as “A singlular expression is required.”
I tried
if (exists wmi) then ((string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) + “x” + (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi)) else (“N/A”)
Q: (if (exists wmi) then (string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) as string else (“N/A”))
A: 1680
A: 1680
I: plural string
Q: ((if (exists wmi) then (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))as string)
A: 1050
A: 1050
I: plural string
(
if (exists wmi) then (string value of select
"ScreenWidth from Win32_DesktopMonitor" of wmi) as string
else (
"N/A")) &
"x" & (
if (exists wmi) then (string value of select
"ScreenHeight from Win32_DesktopMonitor" of wmi)as string
else (
"N/A"))
I’m getting an odd response to the WMI Query on some of the computers.
q: (if (exists wmi) then (string value of select “ScreenWidth from Win32_DesktopMonitor” of wmi) as string else (“N/A”)) & “x” & (if (exists wmi) then (string value of select “ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))
A: 1024x768
E: Singular expression refers to non-unique object.
Most of the systems return an expected value, and even on an erroring machine, I get the response above. I broke each of the seperate WMI queries out and each of them returns the an Error condition along with the correct resolution.
I think the computers that are erroring have two monitors, so each wmi query
string values of select
"ScreenWidth from Win32_DesktopMonitor" of wmi
returns two strings, and two strings cannot be appended to two other strings (relevance doesn’t try to correlate them).
You have to return all the results in one wmi query; I played around with it for a bit and got this:
q: (string value of property
"ScreenHeight" of it &
"x" & string value of property
"ScreenWidth" of it) of select objects
"ScreenWidth, ScreenHeight from Win32_DesktopMonitor" of wmi A: 1200x1600 A: 1200x1600 I: plural string
Which works on both my single monitor computer and dual monitor computer.
(unique values of (string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)
Q: unique values of ((string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)
q: (if (exists wmi) then ((string value of property “ScreenHeight” of it & “x” & string value of property “ScreenWidth” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))
A: 768x1024
E: Singular expression refers to nonexistent object.
This is from a computer with a single monitor. I tried Mark’s code and get an error …
q: unique values of ((string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)
E: Singular expression refers to nonexistent object.
Jeremy’s code …
q: (string value of property “ScreenHeight” of it & “x” & string value of property “ScreenWidth” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi
A: 768x1024
E: Singular expression refers to nonexistent object.
Anyone have any other suggestions? I’d be happy if I could just get ONE screen resolution since there are only a few here that have different resolutions, usually laptops where users have an external monitor they attach at their desks via docking stations.
if (exists wmi AND exists select
"VideoModeDescription from Win32_VideoController" whose (type of it = 8) of wmi) then (preceding text of last
" x" of (string values of selects
"VideoModeDescription from Win32_VideoController" whose (type of it = 8) of wmi))
else (
"N/A")
I found it in an Analysis already in my deployment.
Seems to work very well. There are still some systems that report , but we have such an eclectic mix of systems I’m not surprise or concerned. I’m happy to have numbers for the vast majority of the systems.