Get Primary Monitor Resolution with PowerShell

If you are changing backgrounds on existing computers, it helps to know what resolution is currently in use on the computer so you can put a background on it that looks just right.  This can be very important if it is your updated company logo.

You can easily extract this information with PowerShell. This script will extract the current display resolution of the primary monitor.

#Get Resolution
Add-Type -AssemblyName System.Windows.Forms
$res = [System.Windows.Forms.Screen]::AllScreens | Where-Object {$_.Primary -eq 'True'} | Select-Object WorkingArea
if (($res -split ',')[3].Substring(10,1) -match '}') {$heightend = 3}
else {$heightend = 4}
$w = ($res -split ',')[2].Substring(6)
$h = ($res -split ',')[3].Substring(7,$heightend)
'Screen Resolution: ' + $w + 'x' + $h

 

Comments are closed.