How to use PowerShell to make Spotlight automatically change your backgrounds

  • Windows Spotlight stores images in internal paths without extension and can be used as a source of dynamic backgrounds.
  • With PowerShell it is possible to extract the latest Spotlight image, improve the wallpaper quality and apply it as a background.
  • Scripts and scheduled tasks allow you to automate both the downloading and organization of images and the rotation of the background.
  • Proper Spotlight configuration and maintenance actions (re-registration, SFC) ensure that the system continues to update images.

Change background using PowerShell and Spotlight

Do you love the images that appear on the Windows Spotlight lock screen but are annoyed that you can't use them as your desktop background? Windows doesn't offer a direct option to use those photos as your desktop background , so you'll need to get a little creative and use PowerShell to automate the process.

In this article, you'll see, step by step, how to use PowerShell to have Spotlight automatically change your backgrounds , how Windows Spotlight works internally , where it stores images, how to use them for a slideshow, how to schedule scripts with Task Scheduler, and what to do if Spotlight stops updating photos.

What is Windows Spotlight and how does it work with your funds?

Windows Spotlight is a Windows feature that displays spectacular images on the lock screen daily, often accompanied by short texts with interesting facts, recommendations, suggestions, or even messages from your organization if you are in a corporate environment.

In enterprise environments, Windows Spotlight is only available in the Enterprise and Education editions , where the IT department can centrally control its behavior. At home, most users see it as "the photos that change automatically on the lock screen," although there's much more to it than that.

When Spotlight is enabled, Windows downloads new images almost daily and applies them to both the lock screen and, in some cases, the login screen background. The photos can come from various sources, but the system stores them in specific internal locations that aren't readily apparent to the user.

Furthermore, the user experience can be customized with policies . Your company can decide whether to display only images, add messages, combine them with a static corporate image, and so on. For the advanced user at home, the interesting thing is knowing that those photos are there… and that we can retrieve them with PowerShell.

windows spotlight

Spotlight requirements and basic configuration on Windows

Before we delve into scripts, it's a good idea to make sure Windows Spotlight is enabled and working correctly. Otherwise, there won't be any new images to use for your desktop background. You can also check out some software tips for Windows.

On an individual computer, the easiest way to check this is through Windows settings. You only need access to Settings and Personalization options ; you don't need administrator privileges to use Spotlight at the user level.

If you work in a business or educational institution, enabling or disabling Spotlight may depend on policies enforced through Intune, Group Policy Objects (GPOs), or policy experience content packages (CSPs). In these environments, it's common for administrators to combine Spotlight with corporate images or organizational messaging.

In any case, the starting point is the same: you need Spotlight to be enabled and actually changing the lock screen images . If it isn't, we'll see later how to reactivate it or troubleshoot common issues.

How to activate Windows Spotlight on the lock screen

On a standard PC running Windows 10 or Windows 11, you can activate Spotlight in seconds from the graphical interface. You don't need PowerShell or scripts for this first step ; just follow this short walkthrough of the Settings menu.

Open the Settings app and go to the Personalization section. From there, you can choose the type of background for your lock screen and ensure that Windows uses Spotlight instead of a static image or a manual slideshow.

For more detailed information, go to:

  • Settings > Personalization > Lock screen.
  • In section Background, Select Windows Spotlight Featured Content in the box.

Once this change is applied, Windows will begin downloading and rotating Spotlight images on your lock screen every day. We'll then "reuse" these same images as your desktop background using PowerShell.

In environments with multiple devices, the administrator can choose to configure this using:

  • CSP of experience directive, usually through an MDM solution such as Microsoft Intune.
  • Group Policy (GPO)If the computers are joined to Active Directory or Microsoft, enter a hybrid environment.

In fact, the policies even allow you to replace Spotlight images with a custom background , keeping the messages, suggestions, and other content, but forcing the image to a static corporate image. In that case, although you can still automate the background change with PowerShell, the images will no longer be the dynamic Spotlight backgrounds but the one defined by your organization.

Where does Windows store Spotlight images?

One of the most curious things about Spotlight is that, although it displays very cool photos, it doesn't save them in a "normal" folder with a visible .jpg or .png extension . They all end up in a path within the user's profile, but without a file extension, so it's not immediately obvious that they are images.

Regardless of the source of each photo, Windows stores them in the same location . When you access that folder, you'll see a list of files with cryptic names and no extension. These are the images that Spotlight downloads and updates.

If you wanted to manage them manually, you would have to add an image extension (for example, .jpg) to each file and open them to check their contents. This would be quite tedious if you have dozens of files accumulated.

To avoid this, it's much better to rely on PowerShell to automate the process: detect Spotlight files, assign them an extension, filter those that actually have adequate resolution, and move them to a useful folder , for example, a OneDrive backgrounds folder or another path that suits you.

That's exactly what many scripts shared by the community do: they scan the Spotlight folder, process the files, and leave you with a collection of backgrounds ready to use in any slideshow or as a static background.

CMD and PowerShell: Essential Commands for Any Windows User

PowerShell script to directly use the latest Spotlight image as a background

A rather elegant way to integrate Spotlight with your desktop is to always use the latest Spotlight image as your Windows wallpaper . This way, every time Windows updates the lock screen photo, your desktop background will also update automatically.

This can be done using a PowerShell script that pulls several key pieces of the system: the current user's SID, the corresponding registry branch where Creative/Spotlight metadata is stored, and the desktop background key in the user's profile.

The first thing the script does is obtain the SID of the user who is running the session :

$userSID = (::GetCurrent()).User.Value

Using that SID, it constructs the registry path where Spotlight stores the current lock screen information:

$currentLockscreenRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Creative\$userSID"

Next, it iterates through the entries in that branch of the registry to obtain the list of associated Spotlight images. These keys are usually dated, so the most recent one corresponds to the newest image.

The script retrieves all those subkeys with Get-ChildItem and keeps the last one:

$spotlightImages = Get-ChildItem -Path $currentLockscreenRegPath -Recurse:$false | Select-Object Name
$latestImage = (Get-ItemProperty -Path $spotlightImages.Name.Replace("HKEY_LOCAL_MACHINE","HKLM:") | Select-Object landscapeImage).landscapeImage

The value landscapeImage contains the full path to the image file that Spotlight is using for the panoramic format, which is exactly the one we want as a desktop background.

Adjust the background quality and avoid unnecessary changes

Before applying the new image as the background, it is highly recommended Make sure the wallpaper's JPEG quality is set to maximum.Windows uses a registry key called JPEGImportQuality within HKCU:\Control Panel\Desktop to decide what quality to store the compressed funds.

The script checks if that key exists and, if it is not present, creates it with a value of 100. If it already exists but does not have a value of 100, it updates it to ensure the highest quality of the background image.

if(-not (Get-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality -ErrorAction SilentlyContinue)){
New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality -PropertyType DWord -Value 100
}elseif ((Get-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality).JPEGImportQuality -ne 100){
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name JPEGImportQuality -Value 100
}

This ensures that Spotlight images look sharp and free of excessive compression artifacts when set as desktop background, and if you want to retouch them you can edit photos in Windows.

The next step in the script is to check if the current desktop background already matches the latest Spotlight image . If they match, no further action is required, and the script ends by returning a success code of 0.

To do this, the key is read Wallpaper en HKCU:\Control Panel\Desktop and is compared to the route of $latestImage:

if((Get-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallPaper).WallPaper -eq $latestImage){
return 0
}

If they are different, the script updates the Wallpaper value with the new path and forces an update of the user parameters so that the change is reflected on the screen:

Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallPaper -Value $latestImage

The command that triggers the update is the classic one:

RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True

However, there's a practical detail: this update doesn't always apply on the first try . That's why the script chooses to run the command in a loop up to 60 times, with short intervals of one second, to ensure that the background eventually changes.

for($i = 0; $i -lt 60; $i++){
& RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
Start-Sleep -Seconds 1
}

With this approach, the script becomes "user agnostic" (calculates its SID in real time), updates the background only when there is a new image, and guarantees the best possible quality of the JPEG wallpaper.

Automate the downloading and organization of Spotlight images

Another very interesting strategy is not only to use the latest Spotlight image, but to save all the images that appear in an organized folder with the correct extension, so you can build a collection of backgrounds and use them in a Windows slideshow.

This is usually done using a PowerShell script that visits the internal folder where Windows stores Spotlight files, detects those that are valid as a background (usually panoramic ones with good resolution) , adds the appropriate image extension (usually .jpg) and copies or moves them to another structured folder.

In many cases, this destination folder is defined by default within Pictures > Wallpaper > Spotlight in your OneDrive account. This way, your Spotlight wallpaper collection is synced with the cloud and available on all your devices associated with that account.

If that destination doesn't convince you, you can Edit the script and change the path on the line where the output folder is defined. (for example, line 6 in some shared scripts). Simply open the .ps1 file in Notepad, find that line, and replace the OneDrive path with your desired path (for example, C:\Wallpapers\Spotlight).

After running the script, you'll have a folder full of Spotlight images with the .jpg extension ready to use as an individual background or as part of a slideshow.

Create a slideshow with Spotlight images

Once you have your images organized in a folder, you can tell Windows to use that location as the source for a background slideshow . This way, instead of having a single static background, all the Spotlight photos you've saved will rotate.

To configure it from the Windows interface, go back to Personalization, but this time to the desktop background section. That's where you choose whether you want a static image, a solid color, or a slideshow.

The basic steps are:

  • Opens Settings > Personalization > Background.
  • In the dropdown, choose Slide presentation.
  • In the option to select the folder, Choose the path where the PowerShell script saves the Spotlight images (for example, your OneDrive folder > Pictures > Wallpaper > Spotlight).

From here you can also configure how often you want the background image to change (every minute, every 10 minutes, every hour, etc.) and whether you want Windows to randomly shuffle the order of the photos.

By combining this feature with the script that downloads and organizes the images, you get a virtually automatic system. Windows Spotlight retrieves new photos, the script captures them, and your desktop displays a constantly updated slideshow of those backgrounds.

Schedule the PowerShell script using Task Scheduler

To avoid having to manually run the script every time you want new images or to synchronize the latest image as the background, the ideal solution is to set up a scheduled task in Windows that launches the script at regular intervals.

The Task Scheduler allows you to create these tasks manually or by importing pre-made XML files. Some sources share a ready-to-use XML file that you simply import and associate with the PowerShell script that manages Spotlight images.

The typical sequence for automating this process is:

  • Download the XML file of the scheduled task that provides the script source.
  • Open the Task Scheduler of Windows.
  • use option Import task and select the downloaded XML file.

Once the task is imported, you can adjust the trigger to your liking : for example, every hour, every 15 minutes, or once a day. On the Actions tab, edit the existing action and, in the "Program or script" field, select the PowerShell script you downloaded earlier.

After saving the changes, you can even delete the original XML file , as the task will already be registered in the system. From that point on, the programmer will automatically execute the script according to the schedule you defined.

Change backgrounds and lock screen on managed devices (Intune, enterprises)

In a business environment, the need often arises to configure desktop backgrounds and lock screens on all managed computers, whether with static corporate images or controlled slideshows.

It is common for the administrator to present a scenario where the images are located in a common folder, for example C:\temp\slideshowtest , and they want to deploy a PowerShell script that configures the screensaver, background, and lock screen based on those files.

The general idea is:

  • Copy the desired images to a standard local path on all computers.
  • Create a PowerShell script that selects or browses those images and applies them as background and/or lock screen.
  • Package that script as Intune application or script to deploy it on all managed PCs.

It's entirely possible, and it's often combined with Intune or GPO policies that prevent the user from changing the background to ensure a consistent corporate image. In any case, the PowerShell logic for modifying the keys of HKCU:\Control Panel\Desktop or the specific keys of the lock screen is very similar to what is used when working with Spotlight.

The main difference is that, instead of relying on dynamic images from Windows Spotlight, you use an organization-controlled folder of static images , with the flexibility to configure slideshows, rotations, and so on.

Common problems when updating the background with PowerShell

Using PowerShell to change the wallpaper usually works well, but there are some peculiar behaviors that can be confusing . One of the most common is that, when running several scripts one after the other, the background doesn't seem to update immediately.

Imagine you have five .ps1 files, each pointing to a different PNG . Double-clicking the first one changes the background correctly. Double-clicking the second one seems to do nothing, or the change is delayed.

A common script pattern in these cases is something like:

Function Set-WallPaper($Value){
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters 1, True
}
Set-WallPaper -value "C:\Users\<usuario>\Pictures\fondo1.png"

This approach is correct in essence, but Windows doesn't always react instantly to changes in the registry key . Sometimes it requires a slight delay, an extra refresh, or ensuring that the process doesn't get "stuck" on the same cached image.

That's why you'll see scripts that, instead of calling it just once, UpdatePerUserSystemParameters, They execute the command several times in a loop with short pauses.Just like the example we discussed earlier with Spotlight. This significantly improves the reliability of consecutive background changes.

It's also advisable to avoid relative paths or profiles that change , and to ensure that the images exist in the specified location. If the path is incorrect or the file doesn't exist, the registry will be updated with an invalid path, and the system may not reflect any changes.

With all of this in mind, combining Windows Spotlight with PowerShell lets you move from a static desktop to a fully dynamic and personalized environment : you can directly use the latest Spotlight image as your background, save and organize all your photos for use in slideshows, automate script execution with Task Scheduler, and even extend the concept to corporate environments with Intune and policies. If you pay attention to details like JPEG quality, correct file paths, and background refresh using RUNDLL32, you'll have a very stable system that will automatically change your backgrounds without you having to worry about a thing.

Assign a different background to each desktop on your Windows 6 PC
Related article:
How to assign a different wallpaper to each desktop or monitor in Windows: Complete guide

Add as preferred source in Google