Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Use Get-DisplayResolution in Windows PowerShell

When working with Windows systems, managing and querying display settings can be essential for various administrative tasks. One such task is retrieving the current display resolution of a system. In PowerShell, the Get-DisplayResolution command is not natively available as it might be in other environments or specific modules. However, you can achieve similar functionality using available PowerShell cmdlets and WMI (Windows Management Instrumentation) classes.

Examples:

Example 1: Using PowerShell to Get Display Resolution

To find the display resolution using PowerShell, you can utilize WMI and the Win32_VideoController class. Here's a step-by-step guide:

  1. Open PowerShell with administrative privileges.

  2. Execute the following command:

    Get-WmiObject -Query "SELECT * FROM Win32_VideoController" | Select-Object -Property Name, CurrentHorizontalResolution, CurrentVerticalResolution

    This command queries the Win32_VideoController WMI class and selects the properties related to the display resolution.

  3. The output will display the name of the video controller and the current horizontal and vertical resolution.

Example 2: Using PowerShell with .NET Classes

Alternatively, you can use .NET classes in PowerShell to retrieve the display resolution:

  1. Open PowerShell with administrative privileges.

  2. Execute the following script:

    Add-Type -AssemblyName System.Windows.Forms
    
    # Output will include the Width and Height properties

    This script uses the System.Windows.Forms namespace to access the primary screen's bounds, which includes the width and height (resolution).

Explanation:

  • Get-WmiObject: This cmdlet is used to get instances of WMI classes. In this context, it retrieves information about video controllers, including resolution.
  • Select-Object: This cmdlet selects specific properties of an object. Here, it is used to extract resolution-related properties.
  • Add-Type: This cmdlet adds a .NET type to a PowerShell session, allowing you to use .NET classes directly.
  • System.Windows.Forms.Screen: This .NET class provides information about display screens, including resolution.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.