The Debug Parameter

  • Comments posted to this topic are about the item The Debug Parameter

  • It seems to me that the question is too vague to have a definitive answer because the result can depend on the PowerShell version (Windows PowerShell vs PowerShell) and the function definition itself (usage of the parameter CmdletBindingAttribute or not).

    Just trying to understand the DebugPreference state more, I have these two functions where one function uses the CmdletBinding attribute and the other does not (file attached).

    function Test-DebugPreferenceNoCmdletBinding()
    Write-Output $DebugPreference

    function Test-DebugPreferenceWithCmdletBinding()
    [CmdletBinding()] param()
    Write-Output $DebugPreference

    Write-Host "Test - NoCmdletBinding/NoDebug - DebugPreference: ", (Test-DebugPreferenceNoCmdletBinding)
    Write-Host "Test - NoCmdletBinding/WithDebug - DebugPreference: ", (Test-DebugPreferenceNoCmdletBinding -Debug)

    Write-Host "Test - CmdletBinding/NoDebug - DebugPreference: ", (Test-DebugPreferenceWithCmdletBinding)
    Write-Host "Test - CmdletBinding/WithDebug - DebugPreference: ", (Test-DebugPreferenceWithCmdletBinding -Debug)

    Execute the script using Windows PowerShell (powershell.exe) and PowerShell 7 (pwsh.exe) to see the different results based on the context of the execution engine and the cmdlet binding attribute.


    Really struggled to pick an answer to this one question and I can certainly understand why SilentlyContinue was a popular answer but I thought it was a trick so I went with Continue.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply