Change the desktop wallpaper from PowerShell
There's no Set-Wallpaper cmdlet, but a tiny P/Invoke of SystemParametersInfo does it natively — the forgotten win32 call behind every 'set background' script.
01Command
$ Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;public class W{[DllImport("user32.dll",SetLastError=true)]public static extern bool SystemParametersInfo(int uAction,int uParam,string lpvParam,int fuWinIni);}' -Name W -Namespace Win32; [Win32.W]::SystemParametersInfo(20, 0, 'C:\Pictures\bg.jpg', 3)02What it does
20 is SPI_SETDESKWALLPAPER and 3 combines SPIF_UPDATEINIFILE with SPIF_SENDCHANGE, which both saves the setting and broadcasts it so the desktop updates instantly. Because it's a P/Invoke, the command is longer than typical cmdlets, but it has zero dependencies and works in Windows PowerShell and PowerShell 7 alike. Some picture formats (e.g. HEIC) are rejected — convert to JPG/PNG first — and wallpaper 'fit' settings stay whatever the user chose in Settings.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- SystemParametersInfoA function (winuser.h) | Microsoft LearnEvidence: Microsoft documents the SPI_SETDESKWALLPAPER action (uAction 20) of SystemParametersInfo, which sets the desktop wallpaper and applies via SPIF_UPDATEINIFILE|SPIF_SENDCHANGE (3).
Last verified: 2026-09-17 · Category: Media
06Related solutions
Search inside text files and logs with regex, returning file, line number and match.
Create or update a .zip from any files or folder contents straight from PowerShell.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.