Powershell Invoke-Sqlcmd capture verbose output

According to Capture Warning, Verbose, Debug and Host Output via alternate streams:

…if I wanted to capture verbose output in a script:

stop-process -n vd* -verbose 4>&1 > C:\Logs\StoppedProcesses.log

So, you would do something like

(Invoke-Sqlcmd -Query "PRINT 'Hello World!';" -ServerInstance $Server -verbose) 4> c:\temp\myoutput.txt

Where 4 is the “verbose” stream.

Leave a Comment