Retrieving Connected Monitor Sizes

notarat

2[H]4U
Joined
Mar 28, 2010
Messages
2,501
So...I need to pull a listing of all active computers in my OU and retrieve the screensize of the connected monitor (or monitors)

For you guys who are admins, this isn't difficult. For me, it's simply not "do-able" because I'm not allowed permission to run the script against the computers in my OU. I have to, instead, create the script and then forward it to someone who has appropriate permissions. They simply copy/paste my script like a damn monkey and click "Run".

Because of this insane restriction, I thought I would paste the script here in hopes that someone can give it a look over and maybe run it to let me know if it is properly pulling the information I need.

Code:
Import-Module ActiveDirectory
$computers = (Get-ADComputer -Filter {Enabled -eq 'True'} -searchbase INSERTYOUROUHERE'-searchscope subtree -Properties Name | select-object -expandproperty name)
Write-host $computers
foreach ($Computer in $computers) {
write-host $computers
$output = [PSCustomObject]@{ComputerName = $Computer;MonitorSizes=''}
$oWmi = Get-WmiObject -Namespace 'root\wmi' -ComputerName $Computer -Query "SELECT MaxHorizontalImageSize,MaxVerticalImageSize FROM WmiMonitorBasicDisplayParams";
$sizes = @();
if ($oWmi.Count -gt 1) {
	foreach ($i in $oWmi) {
		$x = [System.Math]::Pow($i.MaxHorizontalImageSize/2.54,2)
		$y = [System.Math]::Pow($i.MaxVerticalImageSize/2.54,2)
       $sizes += [System.Math]::Round([System.Math]::Sqrt($x + $y),0)
	}##endforeach
} else {
	$x = [System.Math]::Pow($oWmi.MaxHorizontalImageSize/2.54,2)
	$y = [System.Math]::Pow($oWmi.MaxVerticalImageSize/2.54,2)
	$sizes += [System.Math]::Round([System.Math]::Sqrt($x + $y),0)
}##endif

$output.MonitorSizes = $sizes
$Msz = ([string] $output.MonitorSizes )
$strDone = "$computer,$Msz"
Add-Content c:\outputfiles\MonitorSizes.txt -value $strdone
}

When I run a slightly modified script (pointed only at my local machine) I get the data in the following format (which is how I want the info displayed)

COMPUTERNAME,24 20

Is it pulling the same info for you, in the same format?
 
Are you wanting the info displayed in the console, dumped to the text file, or both?
As it is, it appears mostly functional. The console doesn't display useful information though - I don't think it's displaying what you want. The output file however, may.
You'll also potentially run into a lot of WMI errors on your $oWmi (not supported and/or RPC server errors are the top two I'd guess).
I'm also unsure how this will handle systems if they have no monitors. On some of my VMs it simply returned <name>,0 - yet others returned values as well (ranging from 19 to 22). However, it also returned <name>,0 for my laptop and HTPC.

I don't have time to really dig into this tonight though to really assist.
 
Are you wanting the info displayed in the console, dumped to the text file, or both?
As it is, it appears mostly functional. The console doesn't display useful information though - I don't think it's displaying what you want. The output file however, may.
You'll also potentially run into a lot of WMI errors on your $oWmi (not supported and/or RPC server errors are the top two I'd guess).
I'm also unsure how this will handle systems if they have no monitors. On some of my VMs it simply returned <name>,0 - yet others returned values as well (ranging from 19 to 22). However, it also returned <name>,0 for my laptop and HTPC.

I don't have time to really dig into this tonight though to really assist.

The console shouldn't display anything (I noticed that I need to remove the two write-host commands I lef in by accident when I pasted the code.

In our company, our computers are forbidden from running VMs so there won't be any of those to worry about. I do understand there will be "some" RPC errors, but I'm not worried about those, either. I have the error handling code removed from the script for clarity's sake. My error handling will record which computers throw RPC or other errors and log those machine names to a separate file so we can put in trouble tickets to get those corrected by our contracted Sys admins (because the script should access all computers with no errors)

So...from reading your post, you say you're seeing output in the following format, correct?

Computername, 19 22 (as examples of a computer with a 19" and 22" monitor connected)

If it's displaying the info as what's shown above, then it's working properly.

The whole reason for posting here and asking for help is because of the way network management responsibilities are set up in my company, I write the scripts, but our contracted Sys Admins are the ones who run them (with totally different permissions than I possess) so it makes it much more difficult to troubleshoot potential script problems.

I appreciate the assistance!
 
The text file generated is how you describe: Computername, #. I'm not sure it's getting the correct information (like I said, it said my laptop and HTPC have no monitors, when they in fact, both do :D)
 
The text file generated is how you describe: Computername, #. I'm not sure it's getting the correct information (like I said, it said my laptop and HTPC have no monitors, when they in fact, both do :D)

I'm not sure why your laptop isn't responding to the WMI query with the connected monitor. At first I thought maybe you're using a docking station but you never mentioned using one.

I know you say your HTPC is connected to a monitor, not a TV. What brand monitor is it?

Just wondering if there's a particular brand/model of monitor that doesn't respond to the query and report the queried values to the OS...
 
The HTPC connects to a monitor or a TV at times - it's in a transitory period right now :D When it's connected to a monitor (which is the present case) it is an ASUS monitor (not sure exact model off the top of my head - would have to check next time I'm home... Monday hah). One thing I didn't yet try, and sadly don't have time to try, is seeing if having the monitor on versus off makes a difference. When I ran it before, the HTPC was powered on, but the monitor was off.

No docking station on the laptop. It is an MSi laptop. It was powered on and in use when the script was ran.

If I get a good break today, and if you want to post the entire script, I'll run it here at work too. That should populate a few thousand rows. It may be "better" to shift and use export-csv than add-content, but that depends slightly on what you want to do with the output file :)
 
Looks like it'll be extremely slow, since it only issues one request at a time. Fails almost always because WMI remoting needs to be turned on for each of the clients. Here's what it wrote to the file for me at home; lots of spew about the WMI failures and repeated the computer list a couple times for each machine enumerated, so error handling and cleanup are obviously an issue.

Code:
PS C:\Users\administrator.PROZAC> type C:\outputfiles\MonitorSizes.txt
RUNOFF,0
GASKET,0
CURBING,0
BURST,20
BURNER,0
LIZARD,0
CHICANE,0
HAIRPIN,0
CALIPER,0
TREAD,0
STINKPAD,0
APEX,20
DOCKER,0
carbon,0
ZINC,30 24
NUCK,20
 
Looks like it'll be extremely slow, since it only issues one request at a time. Fails almost always because WMI remoting needs to be turned on for each of the clients. Here's what it wrote to the file for me at home; lots of spew about the WMI failures and repeated the computer list a couple times for each machine enumerated, so error handling and cleanup are obviously an issue.

Code:
PS C:\Users\administrator.PROZAC> type C:\outputfiles\MonitorSizes.txt
RUNOFF,0
GASKET,0
CURBING,0
BURST,20
BURNER,0
LIZARD,0
CHICANE,0
HAIRPIN,0
CALIPER,0
TREAD,0
STINKPAD,0
APEX,20
DOCKER,0
carbon,0
ZINC,30 24
NUCK,20

WMI Remoting is enabled on all our computers by the image they're built with so it "should" be able to pull the information.

Thanks for running it and posting the formatting of the output. It seems as though the "select-object -expandproperty name" is what was needed to stop it from including the "fieldname" information when it queries each computer.
 
WMI Remoting is enabled on all our computers by the image they're built with so it "should" be able to pull the information.
If WMI remoting is enabled, I'm not sure why you can't test on your own desktop.
 
If WMI remoting is enabled, I'm not sure why you can't test on your own desktop.

Because my computer is on a segregated VLAN which is not allowed to see the rest of the network and because group policy prevents me from querying other computers, even those on my VLAN.

As I said in my first post, I'm allowed to create scripts...not run them myself. Contractual obligations...
 
Back
Top