4

I work on a windows service application which can run scripts on a target machine. One of things I need to do is copy files over from my host machine to the target machine for different users. I have explored several solutions but have not found a good one yet. I am listing all that I have tried. Would appreciate if someone has a different/better solution

  • start-bitstransfer: This service runs under system account. So only services under system account can use it.
  • get-content/set-content: Establish a pssession to the target and use set-content within the session. This approach comsumes lot of memory and takes time. For a 1.02 MB file it took more than 2 minutes.

    measure-command{$outp = icm -Session $s -ScriptBlock {get-content C:\Programdata\karan\bigfile.txt}; $outp > bfile.txt}

    TotalMinutes      : 2.20191604
    TotalSeconds      : 132.1149624
    TotalMilliseconds : 132114.9624
    

    For bigger files, the file has to be loaded in chunks and copied which can take even longer

  • With powershell 3.0 you could use Copy-Item after mapping a network drive with a different credential. But you cannot use multiple users simultaneously which beats the purpose of automation Issue with mapping network drives using New-PSDrive

  • Run a webserver and do a http get/post. This is the fastest and the surest, but we will get into opening ports and firewall issues.
Community
  • 1
  • 1
Madhulika
  • 283
  • 3
  • 11
  • With Robocopy you can also copy the permissions of the files and folders if you want. On top of this, it has an MT (multi threading) switch which speeds up file transfers significantly. – DarkLite1 May 11 '15 at 05:15
  • @DarkLite1 when using different credential robocopy also will need us to map to the target drive (net use). This is definitely not an option during automation considering the limitation on drive letters and the fact that windows does not like the same user to connect more than once to a target using different credentials. – Madhulika May 14 '15 at 11:44

1 Answers1

0

Robocopy is the fastest way, launch Robocopy under different credentials using the Start-Process command

 Start-Process -FilePath "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe" -ErrorAction SilentlyContinue -windowstyle hidden -Credential $credentials -ArgumentList ("-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy ByPass",“Robocopy <command line options>”)

I cannot figure out why it is you need to copy files from your computer to another computer using different credentials every time? this technique in PowerShell should work but maybe better solved by granting a single account the proper access to both locations

beehaus
  • 415
  • 1
  • 4
  • 13
  • This is a requirement for an automation product. The solution can work if the same credentials exist on the host machine and the target machine. It the creds don't exist on the host machine one would not be able to start the powershell process itself. – Madhulika May 21 '15 at 03:01