Error executing SQL script via SMO in PowerShell

Question:

I have some code that loads a script to a variable, and then I pass the variable to an SMO object. I get the following exception:

Exception calling “ExecuteWithResults” with “1” argument(s): “Execute
with results failed for Database ‘Russell_Test’. “

  • $serverName is the server name.
  • $databaseName is the database name.
  • $createScript is the script that was read.

How can I fix this problem?

Below is the relevant portion of the code.

Answer:

Thanks for the help. Ultimately the SMO option would not work so I did this solution:

Source:

Error executing SQL script via SMO in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply