0

I am writing a PowerShell script that needs to be able to download many large files from many servers (i.e. windows server hosts) at once. Many of these servers may be used for important activities and it is therefore important that the transfer method has the ability to fade into the background when load on the servers start to get high.

Here are 3 transfer methods I know of along with reasons why I don't think they're good enough for the job.

BitsTransfer: The first thing that came to mind was BitsTransfer (https://docs.microsoft.com/en-us/powershell/module/bitstransfer/start-bitstransfer?view=win10-ps), however, there is a fatal issue with this approach in that it can't transfer files that're in use for writing by other processes, and a lot of the files that need to be downloaded from the servers will be in such a state. See start-bitstransfer : The process cannot access the file because it is being used by another process for that issue...

Copy-Item: This gives no control over it's priority, and so there exists the potential that a large file transfer could ground a server to a halt whilst it is processing an important load.

Robocopy: Again, I see no mention of priority or background processing.

0

You should be looking to multi-threading, parallel processing, Background Jobs, Runspace Jobs, and Thread Jobs for your use case.

https://randombrainworks.com/2018/01/28/powershell-background-jobs-runspace-jobs-thread-jobs

Your code should first check if the file is in use, and skip the file if it is and place that in a collection, that you are going to use to come back and try again.

Yet, it also seems that you are asking for dynamic throttling based on server resource consumption state, that also would mean you would need separate code to check for that resource state before taking any action and IMHO, queueing is about as close as you'd get.

https://dille.name/blog/2015/09/08/processing-a-queue-using-parallel-powershell-jobs-with-throttling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.