≡ Menu

Powershell: Script to Get Desktop Screen Resolution

The Powershell code described in this article will help you to get screen resolution details of your desktops It uses System.Drawing and System.Windows.Forms namespaces. The Screen class in System.Windows.Forms provides the data we need — that is screen resolution details. This code will also tell you which one is your primary monitor and it’s resolution details.

Code:

function Get-ScreenResolution {            
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")            
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")            
$Screens = [system.windows.forms.screen]::AllScreens            

foreach ($Screen in $Screens) {            
 $DeviceName = $Screen.DeviceName            
 $Width  = $Screen.Bounds.Width            
 $Height  = $Screen.Bounds.Height            
 $IsPrimary = $Screen.Primary            

 $OutputObj = New-Object -TypeName PSobject             
 $OutputObj | Add-Member -MemberType NoteProperty -Name DeviceName -Value $DeviceName            
 $OutputObj | Add-Member -MemberType NoteProperty -Name Width -Value $Width            
 $OutputObj | Add-Member -MemberType NoteProperty -Name Height -Value $Height            
 $OutputObj | Add-Member -MemberType NoteProperty -Name IsPrimaryMonitor -Value $IsPrimary            
 $OutputObj            

}            
}

 

Output:

Hope this helps…

 

Comments on this entry are closed.

  • Vineeth July 16, 2013, 4:45 pm

    Can we also find serial number for a desktop monitor. Please let me know if we can do this using powershell.

  • Neckross October 16, 2013, 2:43 am

    Great work! I have tried your other script Get-IPDetails.ps1 run it against a CSV file with all my computers, it worked like a charm:
    Get-Content “Z:\Resources\Scripts\CHI-ComputerNames.csv” | .\Get-IPDetails.PS1 | ft -AutoSize

    I tried doing the same with this one to get the same result but I have no luck, I’m using:
    Get-Content “Z:\Resources\Scripts\CHI-ComputerNames.csv” | .\Get-ScreenResolution.ps1 | ft -AutoSize

    I get nothing, no errors, no data info.. can you advise?

  • Syparon March 14, 2019, 1:16 pm

    Congratulation for this function.
    This is actually a really good work … Simple … Efficient and the return is just as I expected it !