@@ -18,7 +18,13 @@ function Disable-DbaTraceFlag {
1818 For MFA support, please use Connect-DbaInstance.
1919
2020 . PARAMETER TraceFlag
21- Trace flag number to enable globally
21+ Trace flag number to disable globally
22+
23+ . PARAMETER WhatIf
24+ Shows what would happen if the command were to run. No actions are actually performed.
25+
26+ . PARAMETER Confirm
27+ Prompts you for confirmation before executing any changing operations within the command.
2228
2329 . PARAMETER EnableException
2430 By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
@@ -42,7 +48,7 @@ function Disable-DbaTraceFlag {
4248 Disable the globally running trace flag 3226 on SQL Server instance sql2016
4349
4450 #>
45- [CmdletBinding ()]
51+ [CmdletBinding (SupportsShouldProcess , ConfirmImpact = ' Low ' )]
4652 param (
4753 [parameter (Mandatory , ValueFromPipeline )]
4854 [DbaInstanceParameter []]$SqlInstance ,
@@ -80,18 +86,19 @@ function Disable-DbaTraceFlag {
8086 Write-Message - Level Warning - Message " Trace Flag $tf is not currently running on $instance "
8187 continue
8288 }
83-
84- try {
85- $query = " DBCC TRACEOFF ($tf , -1)"
86- $server.Query ($query )
87- } catch {
88- $TraceFlagInfo.Status = " Failed"
89- $TraceFlagInfo.Notes = $_.Exception.Message
89+ if ($Pscmdlet.ShouldProcess ($instance , " Disabling flag '$tf '" )) {
90+ try {
91+ $query = " DBCC TRACEOFF ($tf , -1)"
92+ $server.Query ($query )
93+ } catch {
94+ $TraceFlagInfo.Status = " Failed"
95+ $TraceFlagInfo.Notes = $_.Exception.Message
96+ $TraceFlagInfo
97+ Stop-Function - Message " Failure" - ErrorRecord $_ - Target $server - Continue
98+ }
99+ $TraceFlagInfo.Status = " Successful"
90100 $TraceFlagInfo
91- Stop-Function - Message " Failure" - ErrorRecord $_ - Target $server - Continue
92101 }
93- $TraceFlagInfo.Status = " Successful"
94- $TraceFlagInfo
95102 }
96103 }
97104 }
0 commit comments