-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
The documentation states:
"The third command writes a debug message. It uses the Debug common parameter to override the value of $DebugPreference and to display the debug messages resulting from this command.
As a result, even though the value of $DebugPreference is SilentlyContinue, the debug message appears.".
This is a bit misleading. The debug switch actually changes the $DebugPreference within the context of that command. Also to be seen in the following example:
function testf {
[cmdletbinding()]
param()
Write-Host "DebugPreference is $DebugPreference"
}
PS C:> testf
DebugPreference is SilentlyContinue
PS C:> testf -debug
DebugPreference is Inquire
PS C:>
Moreover, as seen in the above example, the -debug switch doesn't just "display" the message as is stated in the helptext - it sets $DebugPreference to "Inquire" (for some reason totally different from the verbose switch, which would set it to "continue"), and halts execution to inquire if execution should continue - which is very different when used in scripts, for example.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: ef95204d-9964-c3fb-7e51-854736609b04
- Version Independent ID: 0604419e-8dc3-2a03-4641-cde87780c864
- Content: Write-Debug (Microsoft.PowerShell.Utility)
- Content Source: reference/5.0/Microsoft.PowerShell.Utility/Write-Debug.md
- Product: powershell
- Technology: powershell-cmdlets
- GitHub Login: @JamesWTruher
- Microsoft Alias: jimtru