实现效果:

  批量下载桌面壁纸使用Powershell_编程

实现代码:

function Download-Wallpaper
{
    Param
    (
        [Parameter(Mandatory=$true)]
        $Folder,

        [Parameter(ValueFromPipeline)]
        [int]
        $Page=1
    )

    Begin
    {
        $url="http://wallpaperswide.com/page/$Page"
        $targetExists=Test-Path -Path $Folder
        if(!$targetExists){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-1366x768.jpg')
            $source="http://wallpaperswide.com/download/$filename"
            $TargetPath=Join-Path -Path $Folder -ChildPath $filename
            Invoke-WebRequest -Uri $source -OutFile $TargetPath
        }
    }
    End
    {
        explorer $Folder
    }
}