Reputation: 55
In an attempt to utilize PowerShell to automate a process of pulling down files, doing something with them, and then copying them to somewhere else, I have most of the process working. My only issue I am encountering is I cannot get invoke webrequest to download multiple files.
# Specify variables
$SVN_BASE = "website ommitted"
$SCCM_PATH = "path omitted"
$LOKI_PATH = "path omitted"
$INSTALLER_NAME = "Firefox Setup 58.0.1.exe"
$PROJECT_FOLDER = "mozilla_firefox_rr"
# Set an alias for the executable 7zip to be called to extract files
set-alias 7z "$env:ProgramFiles\7-Zip\7z.exe"
# Create the working directory for the application
new-item -path "$($env:userprofile)\Desktop" -name $PROJECT_FOLDER -itemtype
directory -Force
# Change the directory to the working directory
set-location "$($env:userprofile)\Desktop\$PROJECT_FOLDER"
# Invoke-WebRequest is aka wget. Here, we are downloading the required file
# and placing it into our working directory
Invoke-WebRequest "$SVN_BASE" -outfile ".\"
Invoke-WebRequest "$LOKI_PATH/$INSTALLER_NAME" -outfile
"$($env:userprofile)\Desktop\$PROJECT_FOLDER\$INSTALLER_NAME"
# Extract contents of executable
7z x Firefox*.exe
# Remove contents that aren't needed
Remove-item .\$INSTALLER_NAME
Remove-item "$SCCM_PATH\core" -recurse
Remove-item "$SCCM_PATH\setup.exe" -recurse
# The final step is copying the newly extracted files to the corresponding SCCM directory
copy-item ".\*" -Destination $SCCM_PATH -recurse
The line that I am hoping to utilize to do this is
Invoke-WebRequest "$SVN_BASE" -outfile ".\"
Any suggestions?
Thanks
Upvotes: 4
Views: 22499
Reputation: 2268
Use invoke-webrequest
to find links. You can utilize regex to pull them out. Then you can use start-bitstransfer
to download each find.
Upvotes: 0
Reputation: 521
Invoke-WebRequest performs HTTP operation with Powershell.
Invoke-WebRequest can perform all HTTP methods. You can accomplish every of them using Method parameter (most popular ones are: GET, POST, PUT, DELETE).
In HTTP protocol there is no option to download all files under particular link. If you want to do it you need to 'crawl' through the page. First list the content of the given link and after some kind of parsing website perform foreach loop through links to download each file.
Upvotes: 6