Learn about Windows PowerShell
Summary: Microsoft Scripting Guy, Ed Wilson, talks about how to use Windows PowerShell to discover multi-monitor configuration information on your computer.
Hey, Scripting Guy! I am a long time reader, but a first time writer. I have been following your blog for years. You are awesome! I have become good at navigating around various WMI classes, but I need to find information about multiple monitors that are connected to my laptop running Windows 7. Ideally, I would like to know if it is connected to only the laptop display, or if there is an added monitor. If I can also find the resolution, it would be awesome.
Microsoft Scripting Guy, Ed Wilson, is here. I just got off a LYNC call with my mentee. We were talking about how important our customers are to us. I told him that I simply cannot do my job properly if I do not talk to customers, hear from customers, and speak to customer groups on a regular basis. He is working on a book, and he mentioned that he misses immediate feedback from customers when he is writing. With my blog, I get feedback every day. In fact, I get an email notification when a comment is written to the blog. These comments make the blog better for us all. Also, the email sent to email@example.com is really important because this is where I get many of my ideas for posts.
So BG, thank you for writing.
There are a couple of WMI classes that provide information about resolution and monitors. One of these classes is the Win32_VideoController class. I can query this by using Get-CimInstance in Windows PowerShell 3.0, or I can use Get-WmiObject in Windows 7 with the default Windows PowerShell 2.0. The command is shown here:
Following is the command and its associated output:
By looking at the output, I can see that I am most interested in the caption, and in the CurrentHorizontalResolution and CurrentVerticalResolution properties. I write the query this way:
PS C:\> Get-WmiObject win32_videocontroller | select caption, CurrentHorizontalResolution, CurrentVerticalResolution
The command and its output are as follows:
The cool thing is that I can use a wildcard character and the alias and really shorten this command as shown here:
GWMI win32_videocontroller | select caption, Current*Resolution
So, I have discovered that I have two video controllers on my computer, but both of them are set to use the same resolution.
Well, what about monitors?
To find information about the monitors, I use the Win32_Desktopmonitor WMI class. The query is shown here:
The default display shows information about the screen height and screen width. But this information, for some reason, does not appear for my laptop monitor itself. This is shown in the following image:
Of course, I already have some of this information from the Video Controller. So I can sort of work back and forth with this.
There is a cool WMI class on my laptop running Windows 8 (I’m not sure if it exists on Windows 7 devices). It is in the Root\WMI namespace. The class is WmiMonitorBasicDisplayParams, and it tells me if a display is active. It also tells me the capabilities of that monitor. Using the Get-CimInstance cmdlet produces a nice output (but you can also use Get-WmiObject). Here is the command:
Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams
The command and the output are shown here:
The SupportedDisplayFeatures property returns another object. The easy way to look at this is to store the object in a variable, and then address it directly. This technique is shown in the following image:
BG, that is all there is to using Windows PowerShell to find multi-monitoring information. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
I am working with some of these handy cmdlets, and would like to confirm the last example does indeed work for Windows 7. Regards
However, would like to note that the win32_desktopmonitor does not reflect the fact I have two monitors, whereaws get-ciminstance does.... Once again, that's Windows 7, and one monitor is hooked via VGA - the other, using DisplayPort.
Hi,you can get information more you can see in feature.
Its work in window 7.