---
title: "Enable-DbaTraceFlag"
description: "Enables one or more trace flags globally on SQL Server instances"
url: "https://dbatools.io/Enable-DbaTraceFlag/"
availability: "Windows, Linux, macOS"
tags: ["Diagnostic", "TraceFlag", "DBCC"]
author: "Garry Bargsley (@gbargsley), blog.garrybargsley.com"
source: "https://github.com/dataplat/dbatools/blob/master/public/Enable-DbaTraceFlag.ps1"
last_updated: "2024-01-01"
---

# Enable-DbaTraceFlag

## Synopsis

Enables one or more trace flags globally on SQL Server instances

## Description

Activates trace flags at the global level using DBCC TRACEON, affecting all connections and sessions on the target SQL Server instances.  
Commonly used for troubleshooting performance issues, enabling specific SQL Server behaviors, or applying recommended trace flags for your environment.  
Changes take effect immediately but are lost after a SQL Server restart - use Set-DbaStartupParameter to make trace flags persistent across restarts.  
The function automatically checks for already-enabled trace flags to prevent duplicate operations.

## Syntax

```powershell
Enable-DbaTraceFlag
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-TraceFlag] <Int32[]>
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Enable the trace flag 3226 on SQL Server instance sql2016

```powershell
PS C:\> Enable-DbaTraceFlag -SqlInstance sql2016 -TraceFlag 3226
```

### Example 2: Enable multiple trace flags on SQL Server instance sql2016

```powershell
PS C:\> Enable-DbaTraceFlag -SqlInstance sql2016 -TraceFlag 1117, 1118
```

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

##### -TraceFlag

Specifies one or more trace flag numbers to enable globally across all sessions on the SQL Server instance.  
Use specific trace flag numbers like 3226 (suppress backup log messages), 1117/1118 (tempdb optimization), or 4199 (query optimizer fixes).  
Multiple trace flags can be specified as an array to enable several flags in a single operation.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| 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.

| Property | Value |
| --- | --- |
| 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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

Prompts you for confirmation before executing any changing operations within the command.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**PSCustomObject**

Returns one object per trace flag operation, indicating the result of enabling each trace flag.

**Properties:**

- SourceServer: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name (service name)
- SqlInstance: The full SQL Server instance name (computer\instance)
- TraceFlag: The trace flag number that was enabled or attempted
- Status: The operation status (Successful, Skipped, or Failed)
- Successful: Trace flag was successfully enabled
- Skipped: Trace flag was already enabled globally
- Failed: An error occurred while enabling the trace flag
- Notes: Additional information about the operation result or error message
- DateTime: Timestamp when the operation was executed

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
