Category Archives: Debug

Write-Debug

NAME
    Write-Debug

SYNOPSIS
    Writes a debug message to the console.

SYNTAX
    Write-Debug [-Message] <string> [<CommonParameters>]

DESCRIPTION
    The Write-Debug cmdlet writes debug messages to the console from a script or command.

    By default, debug messages are not displayed in the console, but you can display them by using the Debug parameter or the $DebugPreference Variable.

PARAMETERS
    -Message <string>
        Specifies the debug message to send to the console.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a string that contains a debug message to Write-Debug.

OUTPUTS
    None
        Write-Debug writes only to the debug stream. It does not return any output.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Write-Debug “Cannot open file.”

    Description
    ———–
    This command writes a debug message. Because the value of $DebugPreference is “SilentlyContinue”, the message is not displayed in the console.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$DebugPreference

    SilentlyContinue

    C:\PS> Write-Debug “Cannot open file.”
    C:\PS>

    C:\PS> Write-Debug “Cannot open file.” -Debug
    DEBUG: Cannot open file.

    Description
    ———–
    This example shows how to use the Debug common parameter to override the value of the $DebugPreference Variable for a particular command.

    The first command displays the value of the $DebugPreference Variable, which is “SilentlyContinue”, the default.

    The second command writes a debug message but, because of the value of $DebugPreference, the message does not appear.

    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.

    For more information about the Debug common parameter, see about_CommonParameters.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$DebugPreference

    SilentlyContinue

    C:\PS> Write-Debug “Cannot open file.”
    C:\PS>

    C:\PS> $DebugPreference = “Continue”

    C:\PS> Write-Debug “Cannot open file.”
    DEBUG: Cannot open file.

    Description
    ———–
    This command shows the effect of changing the value of the $DebugPreference Variable on the display of debug messages.

    The first command displays the value of the $DebugPreference Variable, which is “SilentlyContinue”, the default.

    The second command writes a debug message but, because of the value of $DebugPreference, the message does not appear.

    The third command assigns a value of “Continue” to the $DebugPreference Variable.

    The fourth command writes a debug message, which appears on the console.

    For more information about $DebugPreference, see about_preference_variables.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113424
    Write-Verbose
    Write-Error
    Write-Host
    Write-Progress
    Write-Output
    Write-Warning

Debug-Process

NAME
    Debug-Process

SYNOPSIS
    Debugs one or more processes running on the local computer.

SYNTAX
    Debug-Process [-Name] <string[]> [-Confirm] [-WhatIf] [<CommonParameters>]

    Debug-Process [-Id] <Int32[]> [-Confirm] [-WhatIf] [<CommonParameters>]

    Debug-Process -InputObject <Process[]> [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Debug-Process cmdlet attaches a debugger to one or more running processes on a local computer. You can specify the processes by their process name or process ID (PID), or you can pipe process objects to Debug-Process.

    Debug-Process attaches the debugger that is currently registered for the process. Before using this cmdlet, verify that a debugger is downloaded and correctly configured.

PARAMETERS
    -Id <Int32[]>
        Specifies the process IDs of the processes to be debugged. The parameter name (“-Id”) is optional.

        To find the process ID of a process, type “Get-Process“.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -InputObject <Process[]>
        Specifies the process objects that represent processes to be debugged. Enter a Variable that contains the process objects or a command that gets the process objects, such as a Get-Process command. You can also pipe process objects to Debug-Process.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Name <string[]>
        Specifies the names of the processes to be debugged. If there is more than one process with the same name, Debug-Process attaches a debugger to all processes with that name. The parameter name (“Name”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Int32, System.Diagnostics.Process, System.String
        You can pipe a process ID (Int32), a process object (System.Diagnostics.Process), or a process name (String) to Debug-Process.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        This cmdlet uses the AttachDebugger method of the Windows Management Instrumentation (WMI) Win32_Process class. For more information about this method, see “AttachDebugger Method” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143640.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Debug-Process -Name powershell

    Description
    ———–
    This command attaches a debugger to the PowerShell process on the computer.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Debug-Process -Name sql*

    Description
    ———–
    This command attaches a debugger to all processes that have names that begin with “sql”.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Debug-Process winlogon, explorer, outlook

    Description
    ———–
    This command attaches a debugger to the Winlogon, Explorer, and Outlook processes.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Debug-Process -id 1132, 2028

    Description
    ———–
    This command attaches a debugger to the processes that have process IDs 1132 and 2028.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process powershell | Debug-Process

    Description
    ———–
    This command attaches a debugger to the PowerShell processes on the computer. It uses the Get-Process cmdlet to get the PowerShell processes on the computer, and it uses a pipeline operator (|) to send the processes to the Debug-Process cmdlet.

    To specify a particular PowerShell process, use the ID parameter of Get-Process.

    ————————– EXAMPLE 6 ————————–

    C:\PS>$pid | Debug-Process

    Description
    ———–
    This command attaches a debugger to the current PowerShell processes on the computer.

    It uses the $pid automatic Variable, which contains the process ID of the current PowerShell process. Then, it uses a pipeline operator (|) to send the process ID to the Debug-Process cmdlet.

    For more information about the $pid automatic Variable, see about_Automatic_Variables.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Process -computername Server01, Server02 -Name MyApp | Debug-Process

    Description
    ———–
    This command attaches a debugger to the MyApp processes on the Server01 and Server02 computers.

    It uses the Get-Process cmdlet to get the MyApp processes on the Server01 and Server02 computers. It uses a pipeline operator to send the processes to the Debug-Process cmdlet, which attaches the debuggers.

    ————————– EXAMPLE 8 ————————–

    C:\PS>$p = Get-Process powershell

    C:\PS> Debug-Process -inputobject $p

    Description
    ———–
    This command attaches a debugger to the PowerShell processes on the local computer.

    The first command uses the Get-Process cmdlet to get the PowerShell processes on the computer. It saves the resulting process object in the $p Variable.

    The second command uses the InputObject parameter of Debug-Process to submit the process object in the $p Variable to Debug-Process.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135206
    Get-Process
    Start-Process
    Stop-Process
    Wait-Process
    Debug-Process