Get-DisplayResolution : validating results

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of David Stiff David Stiff 1 year, 9 months ago.

  • Author
    Posts
  • #23198
    Profile photo of David Stiff
    David Stiff
    Participant

    Hello,

    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?

    Thanks,
    Dave

  • #23199
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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?

  • #23200
    Profile photo of David Stiff
    David Stiff
    Participant

    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
    SerializationVersion 1.1.0.1
    CLRVersion 4.0.30319.34011
    BuildVersion 6.3.9600.16394
    PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
    PSRemotingProtocolVersion 2.2

    Thanks,
    Dave

  • #23203
    Profile photo of Daniël
    Daniël
    Participant

    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 1280×800 (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.

  • #23236
    Profile photo of David Stiff
    David Stiff
    Participant

    That works. Thanks Daniël!

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

You must be logged in to reply to this topic.