I am trying to write a mysql select statement using the results from a get-childitem cmdlet of a certain folder. I am able to get the results from that cmdlet but do not know how to get each item of the array to be put into the query’s “WHERE” section. The entire query is a string. How do I pass each item of the array into the query’s string in the WHERE section of the query?
I first get the filenames from the directory
$files = Get-ChildItem -Path 'filepath\*.ext' | select -Property name
Here is my code for the query:
$sqlresult = path_to_script\MySQL.ps1 ` -Query "SELECT exp.ExpenseID,exp.ExpenseUserID,exp.ExpenseDate,exp.BudgetEntity,exp.ActivityCode,exp.Amount,User.UserLastName,User.UserFirstName,exp.ReceiptPath FROM Expenses as exp JOIN User on userid = exp.expenseuserid WHERE exp.ReceiptPath ='filepath/filename'"
I’m not sure how to bring the two sections of code together? I am using the MySQL.ps1 script from
and am connecting successfully. I can run each section of code successfully, the query if I enter an exact name in the WHERE section. Any help would be greatly appreciated.