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.

2
  • 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? Commented Oct 9, 2013 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. Commented Oct 9, 2013 at 15:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Now that you mention that, someone had a similar phenomenon some time ago. It seems to have something to do with how PowerShell outputs tabular data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.