Here's what I'm trying to accomplish
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.