Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts

Thursday, September 25, 2008

Getting Screen Resolution with WMI and PowerShell

Getting the screen resolution with PowerShell is quite simple:

param( [string]$strComputer = "." )
$displays
= Get-WmiObject `
-class "Win32_DisplayConfiguration" `
-computername $strComputer

foreach ($display in $displays) {
$obj
= New-Object psObject
$obj
Add-Member NoteProperty DeviceName $display.DeviceName
$obj
Add-Member NoteProperty PelsWidth $display.PelsWidth
$obj
Add-Member NoteProperty PelsHeight $display.PelsHeight
$obj
Add-Member NoteProperty BitsPerPel $display.BitsPerPel
$obj
Add-Member NoteProperty DisplayFrequency $display.DisplayFrequency
Write
-Output $obj
}


Setting the resolution is not so simple. There are a few ways to do this, none of them completely native to PowerShell. You can pass parameters to a compiled executable like this one listed on CodeProject or Qres (Thanks Hal for the links). If warranted, and ambition wasn't an issue, you could write inline C#. Check out Lee Holmes' Invoke-Inline for a wrapper for this.

Enjoy!