Last active
November 26, 2023 10:34
-
-
Save DavidRogersDev/9131afb75aaffa643a84d9bde3ac5d89 to your computer and use it in GitHub Desktop.
Powershell script which downloads the Bing image of the day.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$today = Get-Date | |
$todayFormatted = $today.Year.ToString() + "-" + $today.Month.ToString("D2") + "-" + $today.Day.ToString("D2") | |
$Market = "en-AU" | |
$Resolution = "1920x1200" | |
$ImageFileName = "wallpaper-" + $todayFormatted + ".jpg" | |
$DownloadDirectory = "$env:USERPROFILE\Pictures\Bing Wallpaper" | |
$BingImageFullPath = "$($DownloadDirectory)\$($ImageFileName)" | |
if ((Test-Path $DownloadDirectory) -ne $True) { | |
New-Item -ItemType directory -Path $DownloadDirectory | |
} | |
if((test-Path $BingImageFullPath) -eq $False){ | |
[xml]$Bingxml = (New-Object System.Net.WebClient).DownloadString("http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=$($Market)"); | |
$ImageUrl = "http://www.bing.com$($Bingxml.images.image.urlBase)_$($Resolution).jpg"; | |
Invoke-WebRequest -UseBasicParsing -Uri $ImageUrl -OutFile "$BingImageFullPath"; | |
$wp = Get-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper | |
if ($wp.WallPaper -ne $BingImageFullPath) { | |
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $BingImageFullPath | |
rundll32.exe user32.dll, UpdatePerUserSystemParameters | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment