Get-DisplayResolution : validating results


Get-DisplayResolution is correctly displaying the screen resolution to the console. I would like to validate that within a script.

The value is coming back as 1 2 8 0 x 8 0 0 (spaces or some special char in between the numbers)

How can I validate the value in this System.Object to return True or False based on the resolution being correct?


I’m wondering if you are seeing Unicode output or something. I don’t get that on my computer.

If you run “Get-DisplayResolution | GM” what’s the first line of output?

PS C:\Users\Administrator> Get-DisplayResolution | GM

TypeName: System.String

Name MemberType Definition

Clone Method System.Object Clone(), System.Object ICloneable.Clone()

I am running on Windows 2012 Server R2.

PS C:\Users\Administrator> $PSVersionTable

Name Value

PSVersion 4.0
WSManStackVersion 3.0
CLRVersion 4.0.30319.34011
BuildVersion 6.3.9600.16394
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2


That’s a nasty one, looks like the Get-DisplayResolution outputs ASCII NUL, can be fixed by replacing those characters:

((Get-DisplayResolution)[0] -replace $([char]0)) -eq '1280x800'

This outputs a boolean True if the resolution equals 1280x800 (forum software messes up the code, sorry), note… on my test environment the Get-DisplayResolution outputted an array, so that’s why I’ve selected the first item in the array.

That works. Thanks Daniël!

((Get-DisplayResolution)[0] -replace $([char]0)) -eq '1280`x800'