DisplayConfig PowerShell Module

repository·main·Indexed 41 days ago

https://github.com/martingc94/displayconfig

A PowerShell module for managing Windows display settings, including resolution, refresh rate, scaling, and HDR, built on the Connecting and Configuring Display (CCD) APIs. It supports immediate setting application, batch configuration pipelines to reduce flickering, and the ability to backup and restore configurations via XML.

Tokens
19K
Snippets
83
Records
105
Agent score
45%

What's inside DisplayConfig

  1. Apply multiple settings at once using a configuration pipeline

    main

    To reduce flickering and the time required to change multiple settings, you can pipe a configuration object through multiple commandlets and finish the pipeline with Use-DisplayConfig. This applies all specified settings in a single batch.

    Get-DisplayConfig |
        Set-DisplayResolution -DisplayId 1 -Width 2560 -Height 1440 |
        Set-DisplayRefreshRate -DisplayId 1 -RefreshRate 165 |
        Use-DisplayConfig
  2. Understanding Display IDs

    main

    Display IDs in this module follow logic similar to the Windows Settings app. They are determined by the priority of the output port on the graphics adapter:

    1. Internal displays (laptops)
    2. PC connectors (DVI, DisplayPort)
    3. HDMI
    4. Others

    If multiple displays use the same connector type, Windows assigns an incrementing number for each instance. The only way to change a DisplayId is to physically move the display to a different port on the graphics adapter.

  3. Understand DisplayId numbering logic

    main

    Display IDs in this module use logic similar to the Windows Settings app, but they are not guaranteed to be identical on every system.

    Ordering Priority:

    1. Internal displays (e.g., laptop screens)
    2. PC connectors (DVI, DisplayPort)
    3. HDMI and others

    Handling Multiple Displays on One Connector: If multiple displays use the same connector (e.g., two DisplayPort monitors), Windows assigns an incrementing number for each instance. This number is combined with the priority to determine the final DisplayId.

    Note: The only way to change a display's DisplayId is to physically move it to a different port on the graphics adapter.

  4. Identify and use DisplayId with Enable-DisplayAdvancedColor

    main

    The -DisplayId parameter specifies which display should have HDR enabled.

    Important details about DisplayId logic:

    • The numbering logic is similar to the Windows Settings app, but it is not guaranteed to be identical on every system.
    • Displays are sorted by the output port on the adapter using this priority:
      1. Internal displays (laptops)
      2. PC connectors (DVI, DisplayPort)
      3. HDMI
      4. Others
    • If multiple displays use the same connector type (e.g., two DisplayPort monitors), Windows assigns an incrementing number for each instance, which is combined with the priority to determine the order.
    • The only way to change a DisplayId is to physically move the display to a different port on the graphics adapter.
  5. Understand DisplayId numbering

    main

    The -DisplayId parameter identifies which display(s) to rotate. The numbering logic is similar to the Windows Settings app, but is not guaranteed to be identical on every system.

    Displays are sorted by the output port on the adapter using the following priority:

    1. Internal displays (laptops)
    2. PC connectors (DVI, DisplayPort)
    3. HDMI
    4. Others

    If multiple displays use the same connector type (e.g., two DisplayPort monitors), Windows assigns an incrementing number for each instance. This number is combined with the priority to determine the exact order. The only way to change a DisplayId is to move the display to a different port on the graphics adapter.

  6. Understand DisplayId numbering and logic

    main

    In the DisplayConfig module, DisplayId values follow logic similar to the Windows Settings app, though they are not guaranteed to match on every system.

    How IDs are determined: Displays are sorted by the output port on the graphics adapter using the following priority:

    1. Internal displays (e.g., laptops)
    2. PC connectors (DVI, DisplayPort)
    3. HDMI
    4. Others

    If multiple displays use the same connector (e.g., two DisplayPort monitors), Windows assigns an incrementing number for each instance. This number is combined with the priority to determine the exact DisplayId order.

    Note: The only way to change the DisplayId of a display is to physically move it to a different port on the graphics adapter.

  7. Apply multiple display changes at once to minimize flickering

    main

    To reduce screen flickering and the time required to change settings, avoid applying changes one by one. Instead, pipe the output of Get-DisplayConfig through multiple configuration cmdlets (like Disable-Display, Set-DisplayRotation, or Set-DisplayPrimary) and call Use-DisplayConfig at the end of the pipeline. This applies all modifications in a single operation.

    Get-DisplayConfig | Disable-Display -DisplayId 3 | Set-DisplayRotation -DisplayId 1 -Rotation Rotate90 | Set-DisplayPrimary -DisplayId 2 | Use-DisplayConfig
  8. Set the resolution of specific displays using Set-DisplayResolution

    main

    Use the Set-DisplayResolution cmdlet to change the resolution of one or more displays. The cmdlet operates in two modes: ApplyNow (the default) and Config.

    ApplyNow Mode (Default)

    Use this mode to immediately change the resolution of specific displays using width and height values. This mode is useful for quick, direct changes.

    Config Mode

    Use this mode when you want to apply a pre-constructed DisplayConfig object. This is useful when working with complex configurations retrieved via Get-DisplayConfig.

    Note: When using Config mode with the -ChangeAspectRatio parameter, no further changes can be made to that DisplayConfig object due to API limitations. Use -ChangeAspectRatio as the final step before applying.

    # Example: Change display 3 to 1600 x 900 immediately
    Set-DisplayResolution -DisplayId 3 -Width 1600 -Height 900
  9. Clone displays with Copy-DisplaySource

    main

    The Copy-DisplaySource cmdlet clones the output of one source display to one or more destination displays.

    Usage Modes

    1. ApplyNow (Default): Immediately applies the cloning to the specified displays.

      • Requires -DisplayId (the source) and -DestinationDisplayId (the targets).
      • Use the -DontSave switch to prevent the change from being saved to the configuration database. This allows you to roll back the changes using Undo-DisplayConfigChanges.
    2. Config: Applies the cloning as part of a specific DisplayConfig object.

      • Requires -DisplayId and -DisplayConfig.
      • The -DisplayConfig parameter accepts input from the pipeline.

    Stopping Cloning

    To stop a cloning configuration, you can:

    • Change the display profile to anything other than Clone.
    • Use the Enable-Display cmdlet.
    • Use Enable-Display with the -AsClone switch to clone displays without explicitly specifying a source.
    # Clone the second display to displays 1 and 3 immediately
    Copy-DisplaySource -DisplayId 2 -DestinationDisplayId 1,3
  10. Install the DisplayConfig module

    main

    Install the DisplayConfig module from the PowerShell Gallery to manage display settings such as resolution, scaling, and desktop positions using the Windows CCD (Connecting and Configuring Display) APIs.

    Install-Module DisplayConfig