0

I have below:

$users=get-content "1.txt"

foreach ($user in $users) {
  $source      = Select-String -Path 2.txt -Pattern "$user"
  $destination = Select-String -Path 3.txt -Pattern "$user"

  $src  = $source.Line
  $dest = $destination.Line

  Copy-Item $src $dest -Recurse -Force
} 

1.txt contains few thousands lines with user login on each line, 2.txt and 3.txt contains few tens of thousands lines with UNC Paths with - and . included.

It is working when 2.txt and 3.txt are very small but once they go over few tens maybe hundred PowerShell is saying that it cannot run Copy-Item because it cannot use a system-object as string... the error is with $dest, it does not say anything about $src.

Can you please tell me what is wrong and how should I do it?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 3
    What should happens when multiple lines in `3.txt` match pattern? – user4003407 Apr 16 '16 at 13:27
  • 1
    What your error and PetSerAl are saying is that you are getting multiple matches with your larger data sets. So you data is flawed or your patterns have a margin of error. Look at the output of `$destination.line` at the point of failure and you will see multiple results. – Matt Apr 16 '16 at 15:12
  • Thank you for your feedback. It cannot be because I generated 3 (destination folder in an UNC path) using 1 which contains unique users. But maybe is something wrong with the strings... can one blank space create the problem?... About multiple lines in 3 matching the pattern I did not try yet but when running on few lines a second time, it just recreated the same folder inside the destination folder which was created from the first run. – titirobil Apr 18 '16 at 07:04
  • I am trying to do this with streaming... next time I will run it I will report here – titirobil Apr 22 '16 at 17:26

0 Answers0