CmdID / PowerShell / Cmdlets / Debug
Debug-Runspace
Starts an interactive debugging session with a runspace. PowerShell reference
From the PowerShell reference 6 parameters
What it does
Starts an interactive debugging session with a runspace. The Debug-Runspace cmdlet starts an interactive debugging session with a local or remote active runspace. You can find a runspace that you want to debug by first running Get-Process to find processes associated with PowerShell, then Enter-PSHostProcess with the process ID specified in the Id parameter to attach to the process, and then Get-Runspace to list runspaces within the PowerShell host process. After you have selected a runspace to debug, if the runspace is currently running a command or script, or if the script has stopped at a breakpoint, PowerShell opens a remote debugger session for the runspace. You can debug the runspace script in the same way remote session scripts are debugged. You can only attach to a PowerShell host process if you are an administrator on the computer that is running the process, or you are running the script that you want to debug. Also, you cannot enter the host process that is running the current PowerShell session. You can only enter a host process that is running a different PowerShell session.
Debug-Runspace [-Runspace] <Runspace> [-WhatIf] [-Confirm] [<CommonParameters>]Debug-Runspace [-Name] <String> [-WhatIf] [-Confirm] [<CommonParameters>]Debug-Runspace [-Id] <Int32> [-WhatIf] [-Confirm] [<CommonParameters>]Debug-Runspace [-InstanceId] <Guid> [-WhatIf] [-Confirm] [<CommonParameters>]
Debug a remote runspace
PS C:> Get-Process -ComputerName "WS10TestServer" -Name "powershell"
Handles WS(K) VM(M) CPU(s) Id ProcessName
------- ----- ----- ------ -- -----------
377 69912 63 2.09 2420 powershell
399 123396 829 4.48 1152 powershell_ise
PS C:> Enter-PSSession -ComputerName "WS10TestServer"
[WS10TestServer]:PS C:> Enter-PSHostProcess -Id 1152
[WS10TestServer:][Process:1152]: PS C:\Users\Test\Documents> Get-Runspace
Id Name ComputerName Type State Availability
-- ---- ------------ ---- ----- ------------
1 Runspace1 WS10TestServer Remote Opened Available
2 RemoteHost WS10TestServer Remote Opened Busy
[WS10TestServer][Process:1152]: PS C:\Users\Test\Documents> Debug-Runspace -Id 2
Hit Line breakpoint on 'C:\TestWFVar1.ps1:83'
At C:\TestWFVar1.ps1:83 char:1
+ $scriptVar = "Script Variable"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[Process:1152]: [RSDBG: 2]: PS C:> >IdentifyIts page in the reference: Debug-Runspace.
Parameters
-IdSpecifies the ID number of a runspace. You can run Get-Runspace to show runspace IDs.-InstanceIdSpecifies a runspace by its instance ID, a GUID that you can show by running Get-Runspace.-NameSpecifies a runspace by its name. You can run Get-Runspace to show the names of runspaces.-RunspaceSpecifies a runspace object. The simplest way to provide a value for this parameter is to specify a variable that contains the results of a filtered Get-Runspace command.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.