Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Download-files.ps1
- ## Downloads files from a website
- <#
- Requires:
- inputfile - text file of files to download, 1 URL per line
- outputpath - folder to store downloaded files in
- EG:
- Given a text file called listToDownload.txt containing the following:
- http://www.filesgohere.com/wsus/WSUSMaintenance.zip
- http://www.filesgohere.com/greenshot.exe
- http://www.filesgohere.com/treesizefree.exe
- http://www.filesgohere.com/WSUSMaintenance.zip
- Running the command:
- .\Download-files.ps1 -inputfile listToDownload.txt -outputpath "c:\temp"
- will download the 4 files in the text file and save them in c:\temp. The duplicate file, WSUSMaintenance.zip will have the 2nd copy renamed to "http___www.filesgohere.com__wsusmaintenance.zip"
- EG: duplicates will be renamed to the full URL, excluding NTFS reserved characters (these will be replaced by underscores ("_").)
- #>
- param(
- [string]$inputfile=$(throw "-inputfile parameter is required"),
- [string]$outputpath=$(throw "-outputpath parameter is required")
- )
- $filestodownload=get-content $inputfile
- $splitoption=[System.StringSplitOptions]::RemoveEmptyEntries
- foreach ($webaddress in $filestodownload)
- {
- $filenamearray=$webaddress.split("/",$splitoption)
- $filename=$filenamearray[-1]
- $destination = "$outputpath\$filename"
- if (test-path $destination)
- {
- $destination=$webaddress.replace("<","_")
- $destination=$destination.replace(">","_")
- $destination=$destination.replace(":","_")
- $destination=$destination.replace("`"","_")
- $destination=$destination.replace("/","_")
- $destination=$destination.replace("\","_")
- $destination=$destination.replace("|","_")
- $destination=$destination.replace("?","_")
- $destination=$destination.replace("*","_")
- $destination="$outputpath\$destination"
- }
- Invoke-WebRequest $webaddress -OutFile $destination
- }
Add Comment
Please, Sign In to add comment