PerryW
PerryW

Reputation: 1436

Pausing Powershell after Invoke-Sqlcmd

First time I've used Invoke-Sqlcmd from Powershell and I've hit an annoying challenge. The script works fine but I need to run it from a shortcut with a "do something to continue" pause after it. Should be simple? Normally I do a Read-Host "Press enter to continue" but neither that, nor anything else from How do you do a 'Pause' with Powershell, works.

The output from the invoke-sqlcmd doesn't hit the screen until after the pause, so disappears instantly. Almost like it was acting asynchronously.

I've tried endless variations on:

Write-Host "Query Result:"
Invoke-Sqlcmd -ServerInstance $SQLServer -Database $db3 -Query $qcd -Verbose
Read-Host "Press enter etc..."

The only thing I've found that works is to pipe to a loop that iterates through the resulting Datarow object - that just seems overkill

Upvotes: 0

Views: 210

Answers (1)

PerryW
PerryW

Reputation: 1436

Having spent more time on this than I'd care to admit to, the best I can come up with is:

Write-Host "Query Result:"
$out = Invoke-Sqlcmd -ServerInstance $SQLServer -Database $db3 -Query $qcd -Verbose
Write-Host ($out | Format-Table | Out-String)

Read-Host "Press enter etc..."

I feel that's more of a workaround than an answer though

Upvotes: 0

Related Questions