Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

I seem to be having problems pulling a listing of connected monitor sizes

$
0
0

I'm trying to pull a listing of how many monitors are connected to each computer and the size of each monitor. When I run the script, using my local computer in the input file, the output looks like the following:

Computer855,24 20 --(which is how it's supposed to look)

When I run the script against a text file containing a list of all computers in my Organizational Unit, the output looks like the following:

@{Name=Computer12099},0
@{Name=Computer12954},0
@{Name=Computer12776},0
@{Name=Computer13875},0

(which is how it's NOT supposed to look, and it doesn't record the connected monitor sizes)

There is no difference in the input file, no additional spaces or carriage returns...

What am I doing wrong?

$computers = Get-Content c:\inputfiles\Complist.txt

foreach ($Computer in $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\MonSizes.txt -value $strdone 

}


Viewing all articles
Browse latest Browse all 6937