How to change wallpapers with powershell

Powershell script: Sets a random desktop wallpaper from a specified folder. Date: 23 May 2025 Author: @_jasonturley $WallpaperFolder = "C:\Users\jason\OneDrive\Pictures\Wallpapers\" $WallpaperFile = Get-ChildItem -Path $WallpaperFolder | Get-Random $WallpaperPath = Join-Path -Path $WallpaperFolder -ChildPath $WallpaperFile.Name Using the SystemParametersInfo function from user32.dll to set the wallpaper Add-Type @" using System.Runtime.InteropServices; public class Wallpaper { [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); } "@ $SPI_SETDESKWALLPAPER = 0x0014 $SPIF_UPDATEINIFILE = 0x01 $SPIF_SENDWININICHANGE = 0x02 Change the wallpaper and refresh the desktop [Wallpaper]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $WallpaperPath, $SPIF_UPDATEINIFILE -bor $SPIF_SENDWININICHANGE) 👕Merch: https://shop.jasonturley.xyz/ ==== Social Media ==== 🤖Discord:   / discord   💻Blog: https://jasonturley.xyz/blog 🐔Twitter:   / _jasonturley   🐙GitHub: https://github.com/JasonTurley 🔗LinkedIn:   / jasonturley   ®️ Reddit:   / _jasonturley   ==== Support ==== 💖 Patreon:   / jasonturley   ☕BuyMeACoffee: https://www.buymeacoffee.com/jasonturley 🪙Donate Crypto: https://jasonturley.xyz/donate