在尝试利用 PowerShell 自动化提取文件、对文件执行某些操作,然后将它们复制到其他地方的过程中,我已经完成了大部分过程。我遇到的唯一问题是我无法调用网络请求来下载多个文件。
# 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
Run Code Online (Sandbox Code Playgroud)
我希望用来执行此操作的线路是
Invoke-WebRequest "$SVN_BASE" -outfile ".\"
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
谢谢
Invoke-WebRequest 使用 Powershell 执行 HTTP 操作。
Invoke-WebRequest 可以执行所有 HTTP 方法。您可以使用Method参数来完成其中的每一个(最流行的参数是:GET、POST、PUT、DELETE)。
在 HTTP 协议中,没有选项可以下载特定链接下的所有文件。如果您想这样做,您需要“爬行”页面。首先列出给定链接的内容,然后在某种解析网站后通过链接执行 foreach 循环来下载每个文件。
| 归档时间: |
|
| 查看次数: |
20642 次 |
| 最近记录: |