Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell是否调用Webrequest下载并保存所有文件?_Powershell - Fatal编程技术网

Powershell是否调用Webrequest下载并保存所有文件?

Powershell是否调用Webrequest下载并保存所有文件?,powershell,Powershell,为了尝试利用PowerShell自动执行一个过程,即下拉文件、处理文件,然后将文件复制到其他地方,我让大部分过程都正常工作。我遇到的唯一问题是我无法获得invoke webrequest来下载多个文件 # Specify variables $SVN_BASE = "website ommitted" $SCCM_PATH = "path omitted" $LOKI_PATH = "path omitted" $INSTALLER_NAME = "Firefox Setup 58.0.1.

为了尝试利用PowerShell自动执行一个过程,即下拉文件、处理文件,然后将文件复制到其他地方,我让大部分过程都正常工作。我遇到的唯一问题是我无法获得invoke webrequest来下载多个文件

# 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
我希望使用的线路是

Invoke-WebRequest "$SVN_BASE" -outfile ".\"
有什么建议吗


谢谢,Invoke WebRequest使用Powershell执行HTTP操作

Invoke WebRequest可以执行所有HTTP方法。您可以使用方法参数(最常用的有:GET、POST、PUT、DELETE)来完成所有这些操作

在HTTP协议中,并没有选择下载特定链接下的所有文件。如果你想这样做,你需要在页面中“爬行”。首先列出给定链接的内容,在某种解析之后,通过链接执行foreach循环以下载每个文件


使用
调用webrequest
查找链接。您可以使用正则表达式将其拉出。然后您可以使用
start bitstransfer
下载每个查找

当你说下载多个文件;能否多次运行
调用WebRequest
(即,每个文件的URL运行一次);或者您希望从某个远程目录/给定页面的所有链接项/诸如此类的内容中提取所有子项?@JohnLBevan我希望提取远程目录下的子项。我想我可以把它指向每个文件,但如果我有一个包含50个文件的目录,那就太麻烦了;我对HTTP的理解是,每个资源都需要自己的请求(这可能就是为什么很多人在一个站点上有多个图像时使用Sprite,而不是浏览器在一个请求中下载所有图像文件的集合)。您可以从远程目录中提取链接列表,然后提取每个项目。。。这里给出了该解决方案(即答案的第一部分):ps。您可以避免使用7zip,而是使用PowerShell(v5以后版本)或.net(PSV5之前版本)进行压缩。7-Zip提供更好的压缩效果;但是,如果您想避免任何努力找出相关的路径,或者避免任何超出您控制范围的依赖关系,那么这个选项可能会更好。