Using a PowerShell script to change the lock screen and desktop background in Windows

If you are creating a Windows 10 image, you will benefit from using a PowerShell script to change the lock screen and desktop background to ensure that all the desktops in your environment are uniformly configured to have the same settings. In this particular example, our PowerShell script is going to look something like this:

The value in quotes next to $Wallpaper and $Lockscreen should match the name of the file you are planning to use for the background and lock screen.

In your C:\ drive, create a folder named ‘background’ and copy the files of the background and lock screen images into this folder. Also, copy the file containing your PowerShell script into this folder.

Next, open an administrator PowerShell prompt and type the following command:
set-executionpolicy unrestricted
Enter Y at the prompt.

Now, type the following commands in PowerShell:
cd c:\ background
(Whatever the name of your script is, simply put ./ to run it)

If successful, the PowerShell prompt should look like the following:

Once successful, restart your computer and you should see both the lock screen and desktop background change.

If you ran the script with the incorrect images, or need to undo the changes for whatever reason, search for and open regedit in the start menu to edit the Windows registry.
Then, navigate to: HKCU:\software\microsoft\windows\currentversion\policies\system
Right click on ‘wallpaper’, select ‘modify’, delete the value data, then click OK. Restart your computer, and you can attempt to run the script again with the same process above after you have made the necessary changes.

This is what the location for HKCU:\software\microsoft\windows\currentversion\policies\system looks like. HKCU is listed as “HKEY Current User” under ‘computer’ in regedit.
After you right click on ‘Wallpaper’ and select modify, you can delete the value, click OK, then restart your computer to undo the changes to the background.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.