使用Powershell递归下载Web目录中的所有文件

时间:2016-11-02 12:55:46

标签: powershell

我需要使用(.csv)从受密码保护的网络目录中递归下载某个文件扩展名PowerShell的所有文件。我认为我可以通过使用星号*作为通配符来实现这一点,但是当我试图测试它时,情况似乎并非如此。

Powershell脚本(somescript.ps1):

$currdate = (Get-Date).ToString("yyyyMMdd")
$Username = 'username'
$Password = 'password'

$url1 = "http://some.website/somedirectory/"+$currdate+"/csv/*.csv"

$url1

$path1 = "D:\somedirectory\someotherdirectory\*.csv"

$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username,$Password)
$WebClient.DownloadFile($url1,$path1 )

错误消息:

Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At C:\Users\someuser\somescript.ps1:13 char:1
+ $WebClient.DownloadFile($url1,$path1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

我做错了什么?

0 个答案:

没有答案