Capturing Errors and LoggingCData Cmdlets for Amazon Redshift 2019 - Build 19.0.7354
This section shows how to access the different debug reporting available via PoweShell streams.
Accessing Cmdlet Output From StreamsThe cmdlet writes data to several PowerShell streams, the Output stream, Error stream, Verbose stream, and Debug stream. Streams enable you to pass the cmdlet results down the pipeline while writing logs to a file or the console.
Redirecting Errors and Logs
Only success output and errors are returned by default. However, the cmdlets can write to two other streams, the Verbose stream and, for higher levels of verbosity, the Debug stream.
The cmdlets write the underlying SQL queries and the execution time to the Verbose stream. To obtain the Verbose stream from the cmdlet, add the "-Verbose" flag.
Select-Redshift -Connection $conn -Table "Orders" -Where "ShipCountry = 'USA'" -Verbose
You can capture the output from this stream by using the redirection operator that corresponds to the stream number. The following line uses the "4>" operator to write cmdlet logs to a file:
Select-Redshift -Connection $conn -Table "Orders" -Where "ShipCountry = 'USA'" -Verbose 4> out.txt
The Debug stream (stream 5) contains the same information as the Verbose stream as well as more details including the following:
- Time of execution
- Low-level interaction with the API of the data source
$message = Select-Redshift -Connection $conn -Table "Orders" -Where "ShipCountry = 'USA'" -Debug 5> out.debug.txt