< Back
Read-DbaTraceFile
Post
NAME Read-DbaTraceFile
SYNOPSIS
Reads SQL Server trace files
SYNTAX
Read-DbaTraceFile [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Path] <System.String[]>] [[-Database] <System.String[]>] [[-Login] <System.String[]>] [[-Spid]
<System.Int32[]>] [[-EventClass] <System.String[]>] [[-ObjectType] <System.String[]>] [[-ErrorId]
<System.Int32[]>] [[-EventSequence] <System.Int32[]>] [[-TextData] <System.String[]>] [[-ApplicationName]
<System.String[]>] [[-ObjectName] <System.String[]>] [[-Where] <String>] [-EnableException <Switch>]
[<CommonParameters>]
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.
PARAMETERS
-ApplicationName [<System.String[]>]
Search for results only with specific ApplicationNames. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.String[]>]
Search for results only with specific DatabaseName. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ErrorId [<System.Int32[]>]
Search for results only with specific Errors. Filters 'Error in ($ErrorId)' Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EventClass [<System.String[]>]
Search for results only with specific EventClasses. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EventSequence [<System.Int32[]>]
Search for results only with specific EventSequences. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<System.String[]>]
Search for results only with specific Logins. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ObjectName [<System.String[]>]
Search for results only with specific ObjectNames. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ObjectType [<System.String[]>]
Search for results only with specific ObjectTypes. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<System.String[]>]
Path to the trace file. This path is relative to the SQL Server instance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Spid [<System.Int32[]>]
Search for results only with specific Spids. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-TextData [<System.String[]>]
Search for results only with specific TextData. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Where [<String>]
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
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Security, Trace
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- 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
RELATED LINKS
SYNOPSIS
Reads SQL Server trace files
SYNTAX
Read-DbaTraceFile [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]
<Pscredential>] [[-Path] <System.String[]>] [[-Database] <System.String[]>] [[-Login] <System.String[]>] [[-Spid]
<System.Int32[]>] [[-EventClass] <System.String[]>] [[-ObjectType] <System.String[]>] [[-ErrorId]
<System.Int32[]>] [[-EventSequence] <System.Int32[]>] [[-TextData] <System.String[]>] [[-ApplicationName]
<System.String[]>] [[-ObjectName] <System.String[]>] [[-Where] <String>] [-EnableException <Switch>]
[<CommonParameters>]
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.
PARAMETERS
-ApplicationName [<System.String[]>]
Search for results only with specific ApplicationNames. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.String[]>]
Search for results only with specific DatabaseName. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ErrorId [<System.Int32[]>]
Search for results only with specific Errors. Filters 'Error in ($ErrorId)' Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EventClass [<System.String[]>]
Search for results only with specific EventClasses. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EventSequence [<System.Int32[]>]
Search for results only with specific EventSequences. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<System.String[]>]
Search for results only with specific Logins. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ObjectName [<System.String[]>]
Search for results only with specific ObjectNames. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ObjectType [<System.String[]>]
Search for results only with specific ObjectTypes. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<System.String[]>]
Path to the trace file. This path is relative to the SQL Server instance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Spid [<System.Int32[]>]
Search for results only with specific Spids. Uses IN for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-TextData [<System.String[]>]
Search for results only with specific TextData. Uses LIKE for comparisons.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Where [<String>]
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
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Security, Trace
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- 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
RELATED LINKS