0

Here's what I have:

Add-PSSnapin sqlservercmdletsnapin100
Add-PSSnapin sqlserverprovidersnapin100

Invoke-Sqlcmd -inputfile "somefile0.sql" -Server "server0" -Username user0 -Password password0
Invoke-Sqlcmd -inputfile "somefile1.sql" -Server "server1" -Username user1 -Password password1

Each Invoke-Sqlcmd run by itself runs fine. When placed in a script that reads like above, the last Invoke-Sqlcmd returns no results to the screen.

Bryan Kahlig
  • 19
  • 1
  • 3
  • If the first `Invoke-Sqlcmd` does and the second one doesn't, the problem is most likely with the second SQL script. Did you try running the SQL statements manually? – Ansgar Wiechers Oct 09 '13 at 14:09
  • Thanks for your response! No matter the order of the Invoke-Sqlcmd statements, the first one executed runs just fine. It appears that the second one runs fine as well, but no output is sent to the screen. I've actually proposed an answer below that sets the result of each Invoke-Sqlcmd to a variable and then does a Write-Host on each variable's ItemArray member. Seems to work just fine now. – Bryan Kahlig Oct 09 '13 at 15:29

1 Answers1

1

I figured this out. Turns out that it works well when I return the results of each Invoke-Sqlcmd to a variable and then output the variable. Like this:

Add-PSSnapin sqlservercmdletsnapin100
Add-PSSnapin sqlserverprovidersnapin100

$result0 = Invoke-Sqlcmd -inputfile "somefile0.sql" -Server "server0" -Username user0 -Password password0
$result1 = Invoke-Sqlcmd -inputfile "somefile1.sql" -Server "server1" -Username user1 -Password password1

Write-Host $result0.ItemArray
Write-Host $result1.ItemArray

The output to the screen is now visible, but poorly formatted. That'll get straightened out next.

Bryan Kahlig
  • 19
  • 1
  • 3
  • Now that you mention that, someone had a [similar phenomenon](http://stackoverflow.com/q/18021932/1630171) some time ago. It seems to have something to do with how PowerShell outputs tabular data. – Ansgar Wiechers Oct 09 '13 at 16:40