Powershell: read computer monitor size from WMI script then write in a list -
i need list monitor sizes. found script here
it works single computer. want change import computerlist , export csv.
param($computername = 'computername') $output = [pscustomobject]@{computername = $computername;monitorsizes=''} $owmi = get-wmiobject -namespace 'rootwmi' -computername $computername -query "select maxhorizontalimagesize,maxverticalimagesize 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 $output
example results:
computername monitorsizes
------------ ------------
computername {15, 24}
computername monitorsizes
------------ ------------
pc1 {19}
this easy in powershell. wrap code in foreach
loop , iterate on 1 or more computer names:
param( [string[]]$computername ) foreach($computer in $computername){ $owmi = get-wmiobject -namespace 'root\wmi' -computername $computer -query "select maxhorizontalimagesize,maxverticalimagesize 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 new-object pscustomobject -property @{computername = $computer; monitorsizes = $sizes} }
assuming save file called getmonitorsizes.ps1
, use this:
$names = "server1","server2","server3" .\getmonitorsizes.ps1 -computername $names
or if have file computer name on each line:
$names = get-content '\\server\list.txt' .\getmonitorsizes.ps1 -computername $names
you can pipe resulting objects csv file export-csv
cmdlet:
.\getmonitorsizes.ps1 -computername $names | export-csv .\screensizes.csv -notypeinformation
Comments
Post a Comment