V Krishan
V Krishan

Reputation: 153

Copying a item without waiting

I want to copy a package over the network, which is of several GB and i cant for copying to be completed to continue executing my PS script and the remaining tasks, as they are not dependent. What would be the best way to do this?

Currently i think the best way would be to call another script to execute the copy with no wait. Your thoughts are much appreciated.

Upvotes: 1

Views: 1451

Answers (1)

Ranadip Dutta
Ranadip Dutta

Reputation: 9133

Powershell has lot of options to do that. One simplest approach would be to use the copy as PSJob like:

#Put you script here which you want to do before copying
$source_path = "\\path\to\source\file"
$destination_path = "path\to\destination\file"
Start-Job -ScriptBlock {param($source_path,$destination_path) Copy-item $source_path $destination_path} -ArgumentList $source_path,$destination_path

# Keep Your remaining script here 

or you can do like this

$copyJob = Start-Job –ScriptBlock {  
   $source = "\\path\to\source\file"  
   $target = "path\to\destination\file"   
   Copy-Item -Path $source -Destination $target -Recurse Verbose  
} 

You can use Background Intelligent Transfer Service (BITS) Cmdlets but for that you need to have the module present, then you should

Import-Module BitsTransfer

Upvotes: 3

Related Questions