Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-By DesignThe reported behavior is by design.The reported behavior is by design.
Description
Steps to reproduce
Save this to a file with a .ps1 extension and run it
function Test-DebugMessage
{
[CmdletBinding()]
[OutputType()]
param ()
process
{
Write-Debug ( 'Test Message' )
}
}
Test-DebugMessage -DebugExpected behavior
The following message is emitted
DEBUG: Test Message
Actual behavior
Prompted to continue for every Write-Debug statement. A for "Yes to All" does nothing
DEBUG: Test Message
Confirm
Continue with this operation?
[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): a
Environment data
> $PSVersionTable.GetEnumerator() | ForEach-Object { Write-Host ('{0,26} : {1,-20}' -f $PSItem.Key,($PSItem.Value -join ', ') ) }
PSVersion : 5.1.15063.674
PSEdition : Desktop
PSCompatibleVersions : 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.15063.674
BuildVersion : 10.0.15063.674
CLRVersion : 4.0.30319.42000
WSManStackVersion : 3.0
PSRemotingProtocolVersion : 2.3
SerializationVersion : 1.1.0.1Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-By DesignThe reported behavior is by design.The reported behavior is by design.
Activity
markekraus commentedon Oct 17, 2017
I believe that is by deisgn. you can instead do the following:
And the debug messages will appear without stopping and prompting.
see about_CommonParamters and about_preference_variables
RickFlist commentedon Oct 17, 2017
Okay... Why? What use case demands that all script execution stop when emitting debug messages? How does that use-case compare with the use case of being able to use -Debug without script execution being interrupted? Why doesn't -Verbose cause the same behavior?
There is no way to tell if this is actually a bug or not, so I don't know if I need to continue harping here or take it to User Voice
markekraus commentedon Oct 17, 2017
To distinguish it from
write-verbose. If it acted exactly aswrite-verbosewhat purpose would it serve? Generally you wouldn't keepwrite-debugstatements in code outside of development. You only put it in development to code so you can perform suspend.when it prompts choose suspend then run
$aand see that it is5. runexitand chose the option to continue. At the next prompt choose suspend and run$aand see that it is10. runexitand then chose the option to continue. This provides an easy way to break into the debugger and check the state of or manipulat variables in your code for the purposes of debugging.If you just want information on the screen you have
Write-VerboseandWrite-Information.RickFlist commentedon Oct 17, 2017
Oh also, can you define "By design"? When I hear "by design" I think there is a specification somewhere that says "when you use -Debug we're going to inquire for every single message emission". Is that the case ? What is "By design"?
markekraus commentedon Oct 17, 2017
Todd Lehmann (@RickFlist) I mean it is probably by design because it is officially documented behavior. That's usually a good indication of the design. If the behavior differed from the documented behavior, that would like not be by design or possible a documentation issue.
RickFlist commentedon Oct 17, 2017
Oh. Yes, it's usually an excellent indicator. Whoops. :\
The reasoning is actually there as well, which is awesome.
"The Debug parameter overrides the value of the $DebugPreference variable for the current command, setting the value of $DebugPreference to Inquire. Because the default value of the $DebugPreference variable is SilentlyContinue, debugging messages are not displayed by default."
Any information as to why this doesn't occur with -Verbose? Ostensibly they would work the same way but I don't get prompted with -Verbose. Just curious
RickFlist commentedon Oct 17, 2017
And what about the fact that "A" for "Yes to All" doesn't actually work? e.g. if I have multiple write-debug statements and hit "A" for the first one, I am still prompted for the second one. By design or bug? If the latter I will submit a new bug.
markekraus commentedon Oct 17, 2017
That's also
by design. the "yes to all" works with this usage:It's not for all calls to
Write-Debug, just for all objects passed to the current call toWrite-Debug.RickFlist commentedon Oct 17, 2017
I'll open up a couple User Voice request. Danke.
KirkMunro commentedon Nov 30, 2018
Hey Todd Lehmann (@RickFlist), just FYI, my PR that fixes this behavior was just merged, so in an upcoming release -Debug will simply enable debug message output without any of the prompting that was there before.
RobinWPollard commentedon Jun 7, 2019
You can switch it to output the debug, but not pause ...
KirkMunro commentedon Jun 7, 2019
Robin Pollard (@RobinWPollard) For older releases, that workaround works. In PowerShell 6.2 and later though, there is no need for that workaround.
HQJaTu commentedon Jun 20, 2019
Thanks for that Kirk Munro (@KirkMunro).
Since the pre 6.2 behaviour was very annoying, I simply upgraded to 6.2.1 and continued working with much less friction.