Skip to main content
Pure Technical Services

How-To: Detailed Logging of PowerShell in the SDK v2

Currently viewing public documentation. Please login to access the full scope of documentation.

This article is for the PowerShell SDK version 2.

Almost all PowerShell cmdlets include a common parameter called -Verbose. This parameter allows for the detailed console output of a command as it is issued and processed. The issue with this parameter is that it does not allow for saving the detailed out to a log file for later viewing and parsing. There are a few way to create a session log within a PowerShell session or script, such as using the Start-Transcript cmdlet or utilizing the PSFramework objects.  Pure has created its own PowerShell logging cmdlet called Set-Pfa2Logging that is provides a simple single parameter implementation to facilitate the creation of a session log.

Verbose PowerShell session logging with Set-Pfa2Logging

When the Set-Pfa2Logging cmdlet is used, all commands executed in the current PowerShell session will be written in verbose format to a log file. The cmdlet only accepts a single primary parameter of -LogFilename. The example below will start session logging to a file called session.log.

PS >Set-Pfa2Logging -LogFilename session.log

You can then view the log as you would any other text file.

For the debugging of commands as they are sent to the array, you could use a utility that shows log file entries that happen in real time. With PowerShell, you could use the Get-Content cmdlet as shown here. Using the -Wait parameter will show a continuous live output of the file. To view other options for the Get-Content cmdlet, please refer to this Microsoft article.

PS >Get-Content session.log -Wait

To view only the last 50 lines of a file, use the -Tail parameter.

PS >Get-Content session.log -Tail 50

Using Set-Pfa2Logging will create a continuous log of the entire PowerShell session. There currently is no cmdlet or parameter to stop the logging.