Monthly Archive

Categories

Parallel copy files over remoting session

In response to this post - https://richardspowershellblog.wordpress.com/2015/05/28/copy-files-over-ps-remoting-sessions/

 

I was asked how you could copy files in parallel to multiple machines.

 

As soon as anyone mentions parallelism I think of workflows so I ended up with this

$computers = 'W16TP5TGT01', 'W16TP5TGT02'

workflow parallelcopy {
  param ([string[]]$computername)
  foreach -parallel ($computer in $computername) {
     InlineScript {
       $s = New-PSSession -ComputerName $using:computer
       Copy-Item -Path C:\Scripts\New-NanoMachine.ps1 -Destination C:\Source -ToSession $s
       Remove-PSSession -Session $s
     }
  }
}

parallelcopy -computername $computers

 

A couple of issues I found. First off –Tosession and –FromSession haven’t been added to the Copy-Item workflow activity. This means you have to use an Inline script block to access those parameters

 

Secondly accessing a emoting session created outside of the workflow generates a session busy error when trying to perform the copy so have to move the session creation into the Inline script.

 

If you had a lot of files, or a lot of data, to copy to multiple machines this approach may be worthwhile. For small amounts of data then the approach in the original article is probably best.

Comments are closed.