$Basically what I'm trying to do is:
I'm pulling information from a .csv spreadsheet that contains a list of files that I need. The problem is, the directory they are in contains 16,000+ files! I only need around 4600 of them (as the spreadsheet column only contains that many). I've actually gotten all that part of the code figured out... but where I'm running into issues is when it gets to the "Copy-Item" portion of my code. It runs fine until it hits files that have brackets as part of the filename, so of course it throws errors and doesn't give me what I need. How can I fix this? Mind you, the files needing/being copied CAN'T be renamed. I'm not sure how to use "-LiteralPath" here, if that's a solution. :( Here's my code below:
$Directory = gci D:\Documents\15075_32\
$Destination = "D:\CleanReview"
$ReviewSheet = import-csv 'C:\Users\7cm\Desktop\Internal Review - Emails Removed per Attorney Request.csv'
$BaseItem = foreach($li in $ReviewSheet){$li.Base}
foreach($File in $Directory){
$File.BaseName
foreach($Item in $BaseItem){
if($Item -like $File.BaseName){
$Item
Copy-Item $File.FullName $Destination -Force
}
}
}