Extracting the contents of a trace file
In this recipe, we will extract the contents of a trace file (.trc
) using PowerShell.
Getting ready
We will need to use the x86 version of PowerShell and/or PowerShell ISE for this recipe. This is unfortunate, but some of the classes we need to use are only supported in 32-bit mode.
In this recipe, we
will use a previously saved trace (.trc
) file. Feel free to substitute this with a trace file that you have available.
How to do it...
Let's look at how we can extract the contents of a trace file.
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE (x86).
Import the
SQLPS
module, and create a new SMO Server object:#import SQL Server module Import-Module SQLPS -DisableNameChecking
Import additional libraries. These are needed to use our
TraceFile
andTraceServer
classes. We do this as follows:#load ConnectionInfoExtended, this contains TraceFile class [Reflection.Assembly]::LoadWithPartialName("Microsoft...