Set-ScreenResolution

Sets the resolution of the main monitor- Requires PowerShell V2

 
 
 
 
 
4.5 Star
(19)
Add to favorites
6/30/2010
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Change to best resolution
    1 Posts | Last post April 18, 2017
    • Hello,
      the script works very well if I want to change the resolution to 800x600. but I need the script also to set the highest resolution, but then I'm getting the error message "Failed To Change The Resolution". All lower resolutions offered by the graphics card work. Do you have an idea?
      Thanks
  • Edited to include Refresh Rate
    1 Posts | Last post February 12, 2017
    • Here's a full modified script to include Refresh Rate, thanks Andy and Roget Noprl!
      
      http://pastebin.com/QQkcveSM
  • Compilation errors occurred
    2 Posts | Last post December 06, 2016
    • Hi,
      
      I tried to run this script and I got error:
      
      Add-Type : Cannot add type. Compilation errors occurred.
      At line:122 char:1
      + Add-Type $pinvokeCode -ErrorAction SilentlyContinue
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
          + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
       
      Unable to find type [Resolution.PrmaryScreenResolution].
      At line:123 char:1
      + [Resolution.PrmaryScreenResolution]::ChangeResolution($width,$height)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (Resolution.PrmaryScreenResolution:TypeName) [], RuntimeException
          + FullyQualifiedErrorId : TypeNotFound
      
      Do you know why and how to make it work?
    • I believe you may be running it under another account...it needs to run as the logged in user.
  • Higher Resolution
    1 Posts | Last post August 30, 2016
    • Same question as Majallka really....
      
      I want my script to accomplish the following:
      
      Set the resolution
      Wait
      Launch a program
      Wait in the background until the launched program process closes
      set the resolution back to what it was prior to being launched.
      
      For ease the last part I am setting the resolution as 2560x1440 as that is the general setting I use so it doesn't need to go off and log anything prior to changing then query that afterwards.
      
      The problem is the SET-ScreenResolution function doesn't support these higher resolution monitors.
      
      Can someone point us in the right direction or location in the script for setting the ScreenResolution function where we can allow higher resolutions?
      
      Thanks
  • Any way to modify this script to change refresh rate?
    3 Posts | Last post June 24, 2016
    • I have a UHD TV which I want to set to 3840*2160@25hz . This script didn't provide refresh rate argument, Any way to do this? thanks a lot
      
    • I did some investigation and found out myself. Below is my modified script
      
      Function Set-ScreenResolution { 
       
      <# 
          .Synopsis 
              Sets the Screen Resolution of the primary monitor 
          .Description 
              Uses Pinvoke and ChangeDisplaySettings Win32API to make the change 
          .Example 
              Set-ScreenResolution -Width 1024 -Height 768    -Freq 60    
          #> 
      param ( 
      [Parameter(Mandatory=$true, 
                 Position = 0)] 
      [int] 
      $Width, 
       
      [Parameter(Mandatory=$true, 
                 Position = 1)] 
      [int] 
      $Height,
      
      [Parameter(Mandatory=$true, 
                 Position = 2)] 
      [int] 
      $Freq
      ) 
       
      ...
      
      dm.dmPelsWidth = width; 
                      dm.dmPelsHeight = height; 
                      dm.dmDisplayFrequency = freq;
      ...
      
      
      Add-Type $pinvokeCode -ErrorAction SilentlyContinue 
      [Resolution.PrmaryScreenResolution]::ChangeResolution($width,$height,$freq) 
      } 
      
      Set-ScreenResolution -Width 3840 -Height 2160 -Freq 24
      
      
    • you forgot this part of the code
      
              public class PrmaryScreenResolution 
              { 
                  static public string ChangeResolution(int width, int height, int freq) 
  • higher resolution
    1 Posts | Last post November 23, 2015
    • hej andy
      great script. works nearly perfect. haven an uhd-monitor, max resolution 3840x2160, but with your script i can only change between 2048x1536 and below, with smaler resolution. everything above, like 2560x1440 or 3840x2160 is not possible and he always say "Failed To Change The Resolution".
      Have you an idea, what i can do?
      thanks
      majailka
  • Haves this Script Parameters?
    1 Posts | Last post May 07, 2015
    • and dow to find them?
      
      First of all the good thing - it running and doing what i want.
      Every time i start the Script it turns the screen 90° to right. If i want to turn the screen 90° left i have to run the script three times....
      
      is there a parameter (e.g 270 or so) which i didnt found?
      
      
  • Script does not do anything
    2 Posts | Last post January 07, 2015
    • Hi,
      
      After looking elsewhere and seeing that first you need to activate script execution, i still dont see the screen changing even if i dont get any errors after running it. Is the script suppose to be different under a 64 bit OS,reboot did not do anything as well.
      I did try with and without elevated powershell prompt and still nothing
      
      Any help would be appreciated
    • This is only a function. It needs to be called for it to work. For example (as provide in the code), add this to the end: Set-ScreenResolution -Width 1024 -Height 768  
  • What about dual screens?
    2 Posts | Last post January 07, 2015
    • I am looking for a script to look for a second display (such as a projector), determine the aspect ratio, and,hopefully, put it in its native resolution.
    • I have modified the function to work with multiple monitors and it is available here https://gallery.technet.microsoft.com/scriptcenter/Set-ScreenResolutionEx-54c5de59 .
  • Add option for multiple desktops?
    2 Posts | Last post January 07, 2015
    • I am trying to use this function to set the resolution on multiple monitors.  Could you add an optional parameter so the desktop # can be passed into the function also.  I am not nearly good enough at C# to figure out how to add it myself.
      
      param ( 
      [Parameter(Mandatory=$false, 
                 Position = 0)] 
      [int] 
      $Width = 1024, 
       
      [Parameter(Mandatory=$false, 
                 Position = 1)] 
      [int] 
      $Height = 768
      ) 
      
      Function Set-ScreenResolution { 
      ...
      
      ...
      }
      
      $computer = "."  
      $desktops = Get-WmiObject -Class Win32_DesktopMonitor  
      $hostname = hostname  
        
      # Display desktop details  
      $i=1 # count of desktops on this system  
        
      foreach ($desktop in $desktops) {  
          if ($desktop.ScreenHeight -lt $Height -or $desktop.ScreenWidth -lt $Width){
           Set-ScreenResolution $Width $Height $i
          }  
      $i++
      }  
      
      Thanks.
    • I have modified the function to work with multiple monitors and it is available here https://gallery.technet.microsoft.com/scriptcenter/Set-ScreenResolutionEx-54c5de59 .
      
1 - 10 of 19 Items