passing a parameter to an sql file in powershell (sqlcmd)

lets say I'm trying to run the following .sql file from powershell


Currently this is how I am calling this file

Invoke-Sqlcmd -ServerInstance instance -Database database -Username username -Password password -InputFile basicQuery.sql

If I wanted to select from "myTable" how would I pass that parameter to the sql file?


If the query is as basic as in your example, it would be better to replace the -InputFile parameter with -Query, where you easily can use a variable. E.g.

$tables = "MyTable1","MyTable2"
$tables | Foreach-Object {
   Invoke-Sqlcmd -ServerInstance instance -Database database -Username username -Password password -Query "SELECT * FROM $_"

For more advanced queries, you could do a file search replace:

Get-Content sqlTemplate.sql | Foreach-Object {
   $_ -replace "TABLE", "MyTable" | Out-File myQuery.sql -Append
Invoke-Sqlcmd -ServerInstance instance -Database database -Username username -Password password -InputFile myQuery.sql

Need Your Help

Using a cronjob to update and display results of a MySQL query

php html mysql ajax node.js

Im having some trouble how I could realize it to have a dynamic website where the data is fetched via ajax to the user.

SOAP call between 2 applications, both deployed on Websphere application server - SSL/HTTPS enabled

java web-services soap websphere soap-client

I am facing an issue - I have two java application e1 and e2 deployed on WebSphere application servers was1_6.x and was2_7.x respectively, both WAS are SSL/HTTPS enabled.