0

I have tried below code and I'm getting this error message. But I'm getting the output generated, is there any way to avoid the error?

Invoke-expression (sqlcmd -S Servername -d DBName -i "D:\Test\Test_files\sample.sql" -h-1 -o "D:\Test\Test_files\test\testfile1.txt")

Error:Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.

Yamini
  • 1
  • 1
    Why do you need `Invoke-Expression` at all if you just can run `sqlcmd` already? Now you just run sqlcmd, and the output of the execution will be input for Invoke-Expression – Michaël Hompus Aug 17 '22 at 11:22
  • As MichaëlHompus notes, you can simply _remove_ `Invoke-Expression` (and the surrounding `(...)`) from your command. Some general advice: [`Invoke-Expression` (`iex`) should generally be avoided](https://stackoverflow.com/a/51252636/45375); definitely [don't use it to invoke an external program or PowerShell script](https://stackoverflow.com/a/57966347/45375). – mklement0 Aug 17 '22 at 11:55

0 Answers0