I'm trying to prepend a PatientOrderNumber to the name of files in a directory if the file name includes a unique ID from my CSV file. I've tried the -like and -contains parameters and have not been successful.
here is my code:
$csvPath = "C:\Users\dougadmin28\Desktop\Test\1bs4e.csv"
## Variable to hold path of Files that need to be renamed ##
$filePath = "C:\Users\dougadmin28\Desktop\Node Modify File Name App\pdfs"
$csv = Import-Csv $csvPath #| Select-Object -Property PatientOrderNumber, FileID, DocumentID, LastName, FirstName|Export-Csv 'C:\Users\dougadmin28\Desktop\Node Modify File Name App\documents.csv'
$files = Get-ChildItem $filePath
foreach ($item in $csv){
foreach($file in $files) {
if($file.FullName -contains '*$item.DocumentID*') {
Rename-Item $file.FullName -NewName "$($item.PatientOrderNumber+"_"+($item.FileID)+'_'+($item.DocumentID)+'_'+($item.LastName)+'_'+($item.FirstName)+($file.extension))"
}#End forEach
}#End if
} #End forEach```