commands

^

Read-DbaTraceFile

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Read-DbaTraceFile on GitHub.
Want to see the Bill Of Health for this command? Check out Read-DbaTraceFile.

Synopsis

Reads SQL Server trace files

Description

Using the fn_trace_gettable function, a trace file is read and returned as a PowerShell object

This function returns the whole of the trace file. The information is presented in the format that the trace subsystem uses.

Syntax

Read-DbaTraceFile
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Path] <String[]>]
    [[-Database] <String[]>]
    [[-Login] <String[]>]
    [[-Spid] <Int32[]>]
    [[-EventClass] <String[]>]
    [[-ObjectType] <String[]>]
    [[-ErrorId] <Int32[]>]
    [[-EventSequence] <Int32[]>]
    [[-TextData] <String[]>]
    [[-ApplicationName] <String[]>]
    [[-ObjectName] <String[]>]
    [[-Where] <String>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Read-DbaTraceFile -SqlInstance sql2016 -Database master, tempdb -Path C:\traces\big.trc

Reads the tracefile C:\traces\big.trc, stored on the sql2016 sql server. Filters only results that have master or tempdb as the DatabaseName.

Example: 2
PS C:\> Read-DbaTraceFile -SqlInstance sql2016 -Database master, tempdb -Path C:\traces\big.trc -TextData 'EXEC SP_PROCOPTION'

Reads the tracefile C:\traces\big.trc, stored on the sql2016 sql server.
Filters only results that have master or tempdb as the DatabaseName and that have 'EXEC SP_PROCOPTION' somewhere in the text.

Example: 3
PS C:\> Read-DbaTraceFile -SqlInstance sql2016 -Path C:\traces\big.trc -Where "LinkedServerName = 'myls' and StartTime > '5/30/2017 4:27:52 PM'"

Reads the tracefile C:\traces\big.trc, stored on the sql2016 sql server.
Filters only results where LinkServerName = myls and StartTime is greater than '5/30/2017 4:27:52 PM'.

Example: 4
PS C:\> Get-DbaTrace -SqlInstance sql2014 | Read-DbaTraceFile

Reads every trace file on sql2014

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByPropertyName)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline true (ByPropertyName)
Default Value
-Path

Path to the trace file. This path is relative to the SQL Server instance.

Alias
Required False
Pipeline true (ByPropertyName)
Default Value
-Database

Search for results only with specific DatabaseName. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-Login

Search for results only with specific Logins. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-Spid

Search for results only with specific Spids. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-EventClass

Search for results only with specific EventClasses. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-ObjectType

Search for results only with specific ObjectTypes. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-ErrorId

Search for results only with specific Errors. Filters 'Error in ($ErrorId)' Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-EventSequence

Search for results only with specific EventSequences. Uses IN for comparisons.

Alias
Required False
Pipeline false
Default Value
-TextData

Search for results only with specific TextData. Uses LIKE for comparisons.

Alias
Required False
Pipeline false
Default Value
-ApplicationName

Search for results only with specific ApplicationNames. Uses LIKE for comparisons.

Alias
Required False
Pipeline false
Default Value
-ObjectName

Search for results only with specific ObjectNames. Uses LIKE for comparisons.

Alias
Required False
Pipeline false
Default Value
-Where

Custom where clause - use without the word "WHERE". Here are the available columns:
TextData
BinaryData
DatabaseID
TransactionID
LineNumber
NTUserName
NTDomainName
HostName
ClientProcessID
ApplicationName
LoginName
SPID
Duration
StartTime
EndTime
Reads
Writes
CPU
Permissions
Severity
EventSubClass
ObjectID
Success
IndexID
IntegerData
ServerName
EventClass
ObjectType
NestLevel
State
Error
Mode
Handle
ObjectName
DatabaseName
FileName
OwnerName
RoleName
TargetUserName
DBUserName
LoginSid
TargetLoginName
TargetLoginSid
ColumnPermissions
LinkedServerName
ProviderName
MethodName
RowCounts
RequestID
XactSequence
EventSequence
BigintData1
BigintData2
GUID
IntegerData2
ObjectID2
Type
OwnerID
ParentName
IsSystem
Offset
SourceDatabaseID
SqlHandle
SessionLoginName
PlanHandle
GroupID

Alias
Required False
Pipeline false
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False