Cmdlets for DB2

Build 23.0.8839

Capturing Errors and Logging

This section shows how to access the different debug reporting available via PoweShell streams.

Accessing Cmdlet Output From Streams

The 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.

Verbose 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-DB2 -Connection $conn -Table "\"Sample\".\"DB2INST1\".Books" -Where "Category = 'US'" -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-DB2 -Connection $conn -Table "\"Sample\".\"DB2INST1\".Books" -Where "Category = 'US'" -Verbose 4> out.txt

Debug Stream

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
To redirect the Debug stream, use the "5>" redirection operator.
$message = Select-DB2 -Connection $conn -Table "\"Sample\".\"DB2INST1\".Books" -Where "Category = 'US'" -Debug 5> out.debug.txt

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839