批量下载桌面壁纸使用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
    }
}
原文地址:https://www.cnblogs.com/feiyucha/p/11188371.html