Feb 22 2012 3:32PM GMT
Posted by: Richard Siddaway
BITS, PowerShell
Download multiple files by BITS
Posted by: 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




