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?