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-GoogleSheets -Connection $conn -Table "Spreadsheet1_Sheet1" -Where "Column2 = 'Bob'" -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-GoogleSheets -Connection $conn -Table "Spreadsheet1_Sheet1" -Where "Column2 = 'Bob'" -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
- Cache queries
$message = Select-GoogleSheets -Connection $conn -Table "Spreadsheet1_Sheet1" -Where "Column2 = 'Bob'" -Debug 5> out.debug.txt