I am going through your CBT nuggets for PowerShell tool making and I am stuck at updating the SQL Table. The function is able to get the computer names fine but just doesn’t update the table.
Keep getting the below error:
Exception calling “ExecuteNonQuery” with “0” argument(s): “Incorrect syntax near the keyword ‘WHERE’.”
At C:\Users\mohammed\Documents\WindowsPowerShell\Modules\MOLDatabase\MOLDatabase.psm1:55 char:9
We don’t support .PSM1 attachments; you need to change it to a TXT. You can also just paste your SQL query in your message, if you like. You’ve got an error in the WHERE portion of it.
When I’m building a SQL statement with variables:
$sql = "UPDATE x SET y = $y, z = $z WHERE a = '$a'"
I’ll usually output that string just so I can see the final query with the variables expanded:
Write-Verbose $sql
I find that often makes the error a lot more obvious. If you can do something similar, I can probably help you pin down the SQL error. You might need to do this in the MOLDatabase module, since it’s building the query based on the data you’re sending it.