powershell to set second monitor wallpaper

shark wsk 96 Reputation points

I have Windows 10 laptop connected to two monitors in extended display mode. I would like to only set the second monitor wallpaper to a specific image.

Manual way of doing this would be to navigate: Desktop right click --> Personalization --> Choose the picture --> Right click and set for monitor 2

Is there any way to automate it via a script (bat/powershell) ?

I was able to get below code snippet to work, however it sets the wallpaper to both the displays

function Set-Wallpaper($MyWallpaper){
$code = @' 
using System.Runtime.InteropServices; 
namespace Win32{ 

     public class Wallpaper{ 
        [DllImport("user32.dll", CharSet=CharSet.Auto)] 
         static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ; 

         public static void SetWallpaper(string thePath){ 

add-type $code 

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,180 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. shark wsk 96 Reputation points

    Any feedback..

    0 comments No comments