Get-DisplayResolution : validating results

Welcome Forums General PowerShell Q&A Get-DisplayResolution : validating results

This topic contains 4 replies, has 3 voices, and was last updated by

3 years, 11 months ago.

  • Author
  • #23198

    Points: 0
    Rank: Member


    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?


  • #23199

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 0
    Rank: Member

    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


  • #23203

    Points: 0
    Rank: Member

    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

    Points: 0
    Rank: Member

    That works. Thanks Daniël!

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

The topic ‘Get-DisplayResolution : validating results’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort