Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Extracting the contents of a trace file


In this recipe, we will extract the contents of a trace (.trc) file 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 that 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 is available.

How to do it...

Let's take a look at how we can extract the contents of a trace file:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Import additional libraries. These are needed to use our TraceFile and TraceServer classes. We do this as follows:

    Add-Type -AssemblyName "Microsoft.SqlServer.ConnectionInfo, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
    
    Add-Type -AssemblyName "Microsoft.SqlServer.ConnectionInfoExtended,  Version=12.0.0.0, Culture...