Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-debug requesting confirmation

I have a simple script running in Powershell 3.0 :

# Testing write-debug [CmdletBinding()] param() write-debug "Debug message" Write-Output "General output"

When I run it without parameters, I get the desired output:

PS C:\scripts\Test> .\debugtest.ps1
General output

When I run it with the -debug parameter, Powershell asks me to confirm after printing the Debug message:

PS C:\scripts\Test> .\debugtest.ps1 -Debug
DEBUG: Debug message

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"):
General output

Why am I being asked to confirm? Shouldn't write-debug simply write the debug output and continue with the script?

Update: $DebugPreference is set to SilentlyContinue:

PS C:\scripts\Test> $DebugPreference
SilentlyContinue
PS C:\scripts\Test> .\debugtest.ps1 -Debug
DEBUG: Debug message

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"):
General output
like image 258
The Joker Avatar asked May 23 '14 01:05

The Joker


People also ask

How do you politely ask for confirmation?

By asking the customer, “Can you please confirm your first and last name?” or “Can you confirm the last four digits of your social security number?” you are politely asking them to verify their identity. Once this step is done, you can move forward and continue helping the customer resolve their issue.

How do I ask my HR for a confirmation letter?

Start by contacting the human resources department. They may have a company policy that requires your written permission before they can send any information to the organization requesting verification.

How do you politely ask for Acknowledgement in an email?

“Please confirm upon receipt” is the correct sentence. This sentence is asking the recipient to tell the person who sent the item to confirm or tell them that they have received the item. Means: “kindly, acknowledge receipt of this email” or “Please confirm receipt”. It is often used in letters and emails.


1 Answers

It sounds like your $DebugPreference variable is set to 'Inquire'.

From Get-Help about_preference_variables:

$DebugPreference
------------------
    Determines how Windows PowerShell responds to debugging messages 
    generated by a script, cmdlet or provider, or by a Write-Debug
    command at the command line. 

    Some cmdlets display debugging messages, which are typically very
    technical messages designed for programmers and technical support
    professionals. By default, debugging messages are not displayed, 
    but you can display debugging messages by changing the value of 
    $DebugPreference.

    You can also use the Debug common parameter of a cmdlet to display
    or hide the debugging messages for a specific command. For more 
    information, type: "get-help about_commonparameters".

    Valid values:
     Stop:               Displays the debug message and stops 
                            executing. Writes an error to the console.

     Inquire:            Displays the debug message and asks you
                            whether you want to continue. Note that
                            adding the Debug common parameter to a
                            command--when the command is configured
                            to generate a debugging message--changes
                            the value of the $DebugPreference variable
                            to Inquire.

     Continue:           Displays the debug message and continues
                            with execution.

     SilentlyContinue:   No effect. The debug message is not 
        (Default)           displayed and execution continues without
                            interruption.

Edit: -Debug is also a cmdlet Common Parameter, and by adding CmdletBinding(), it is also a Common Parameter of your script.

From Get-Help about_common_parameters:

COMMON PARAMETER DESCRIPTIONS

-Debug[:{$true | $false}]
    Alias: db

    Displays programmer-level detail about the operation performed by the
    command. This parameter works only when the command generates
    a debugging message. For example, this parameter works when a command
    contains the Write-Debug cmdlet.

    **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.

    Valid values:

        $true (-Debug:$true). Has the same effect as -Debug.

        $false (-Debug:$false). Suppresses the display of debugging
        messages when the value of the $DebugPreference is not
        SilentlyContinue (the default). 
like image 78
mjolinor Avatar answered Sep 20 '22 11:09

mjolinor