Automatic Wallpaper Downloader

by Mar 2, 2018

Are you tired of boring wallpapers for your desktop? PowerShell can get you new wallpapers! Here’s the function:

function Download-Wallpaper
{
    param
    (
        [string]
        [Parameter(Mandatory)]
        $Folder,
 
        [Parameter(ValueFromPipeline)]
        [Int]
        $Page=1
    )
    
    begin
    {
        $url = "http://wallpaperswide.com/page/$Page"
        $targetExists = Test-Path -Path $Folder
        if (!$targetExists) { $null = New-Item -Path $Folder -ItemType Directory }
    }
    process
    {
        $web = Invoke-WebRequest -Uri $url -UseBasicParsing
 
        $web.Images.src | 
        ForEach-Object {
    
            $filename = $_.Split('/')[-1].Replace('t1.jpg','wallpaper-5120x3200.jpg')
            $source = "http://wallpaperswide.com/download/$filename"
    
            $TargetPath = Join-Path -Path $folder -ChildPath $filename
 
            Invoke-WebRequest -Uri $source -OutFile $TargetPath
        }
    }
    end
    {
        explorer $Folder
    }
}

And this is how you can use it:

 
PS> Download-Wallpaper -Folder c:\wallpapers

It downloads all wallpapers from a public wallpaper website to a local folder, then opens the folder. All you need to do is right-click the wallpaper of choice and choose “Set as Desktop Background”.

By default, Download-Wallpaper downloads the wallpapers from the first page. With the -Page parameter, you can scrape wallpapers from additional pages. Try this:

 
PS> Download-Wallpaper -Folder c:\wallpapers   

Are you an experienced professional PowerShell user? Then learning from default course work isn’t your thing. Consider learning the tricks of the trade from one another! Meet the most creative and sophisticated fellow PowerShellers, along with Microsoft PowerShell team members and PowerShell inventor Jeffrey Snover. Attend this years’ PowerShell Conference EU, taking place April 17-20 in Hanover, Germany, for the leading edge. 35 international top speakers, 80 sessions, and security workshops are waiting for you, including two exciting evening events. The conference is limited to 300 delegates. More details at www.psconf.eu.

Twitter This Tip! ReTweet this Tip!