Reputation: 1483
I currently have:
(invoke-sqlcmd -inputfile (Join-Path $FileDirectory $FileName) -ServerInstance $ServerName -verbose) > $OutFileName
To which I'm getting the output:
VERBOSE: Changed database context to 'BLUELABEL'
I'm trying to use the verbose output to write to the file designated by the Join-Path function.
What am I doing wrong?
(Using PowerShell V3)
I did find this question with answers, but it seems different and I can't seem to apply the same ideas: Powershell Invoke-Sqlcmd capture verbose output
Upvotes: 0
Views: 3030
Reputation: 1483
I ended up getting
sqlps -Command "&{invoke-sqlcmd -inputfile (Join-Path $PSScriptRoot $file) -ServerInstance $server -verbose}" *> "$PSScriptRoot\SqlLog_$file`_$(get-date -f yyyy-MM-dd-hh-mm-ss).txt"
to work.
Originally I was calling another script and passing in 3 variables to it, and running the invoke-sqlcmd call. For some reason that caused me to be unable to use the "*>" or any character combined with the ">".
Maybe someone else can elaborate on why exactly this is the case.
Upvotes: 1
Reputation: 200573
Verbose output is written to a different stream than regular output. The >
operator redirects only the success output stream. To redirect the verbose output stream you need
(...) 4> $OutFileName
or
(...) 4>&1 > $OutFileName
if you want to combine success and verbose output streams.
See about_Redirection for further information.
Upvotes: 1