0

Here's what I'm trying to accomplish

  1. run sql query - result output to txt file
  2. results of txt file to array
  3. get child item- folders and files in the directory if the folder name matches a value from the array
  4. copy items that are returned in step 3 to another directory

The problem I am having is filtering the items in the directory based on the values of the array

gci $sourcepath -recurse | where {$_.name -like $idlist} | Copy-Item -Destination $DestinationHistoryPath
2
  • What is $idlist? Please provide a minimal reproducible example. Commented Mar 23, 2021 at 23:17
  • I'll echo what @zett42 has said. I'll go one step further and ask if you've checked into the -in comparison? Commented Mar 23, 2021 at 23:23

1 Answer 1

1

I'm assuming you've already loaded up the array properly. You don't want the -like operator for this particular scenario. You are better off with -in or -Contains. Something like below may work:

Get-ChildItem $sourcepath -Recurse | 
Where-Object {$_.Name -in $idlist} | 
Copy-Item -Destination $DestinationHistoryPath

If you use contains you'll need to switch the operands like:

Get-ChildItem $sourcepath -recurse | 
Where-Object { $idlist -contains $_.Name } | 
Copy-Item -Destination $DestinationHistoryPath
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.