PowerShell for Windows Admins

Feb 22 2012   3:32PM GMT

Download multiple files by BITS

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Last time we looked at BITS we saw how to transfer a single file. The example in the help file doesn’t work in my environment so this is what I came up with as a work around

Import-Module BitsTransfer -Force            
$computername = "WebR201"            
$destination = "c:\source\transfer\"            
Get-WSManInstance -ResourceURI wmicimv2/* -Enumerate -Dialect WQL `
 -Filter "SELECT * FROM CIM_DATAFILE WHERE Drive='C:' AND Path='\\Transfer\\' " `
  -ComputerName $computername  |            
foreach {            
$name = Split-Path -Path $($_.Name) -Leaf            
$source =  "http://webr201/transfer/$name"            
Write-Host "Transferring $source to $destination"            
Start-BitsTransfer -Source $source -Destination $destination             
Test-Path -Path ($destination + $name) -Verbose            

Import the module

The use WMI over WSMAN cmdlets to find the files in the folder – this assumes that I know the physical path to the virtual directory – within my enterprise there’s no reason why I shouldn’t.

For each of the files I create the URL to the file – use Write-Host to put out a message and then use Test-Path on the destination folder to determine that it has arrived

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: