Skip to content

Add a way to see if a remote debugger has attached #21392

Closed

Description

Summary of the new feature / enhancement

As a user who may want to attach to an otherwise unattended process to debug it, I want to be able to pause execution in said unattended process until I'm able to attach to it.

Proposed technical implementation details (optional)

A common pattern in C# for this would be something like

while (!Debugger.IsAttached) Thread.Sleep(200);
RestOfCodeHere(); // breakpoint on this line

Currently in PowerShell there's no supported way to tell if a debugger is attached to the current runspace. A minimal way to enable this scenario would be a property on Runspace:

public partial abstract class Runspace
{
+   public bool IsRemoteDebuggerAttached { get; }
}

This would allow the user to write the code

while (-not $Host.Runspace.IsRemoteDebuggerAttached) { Start-Sleep -Milliseconds 200 }
Invoke-RestOfCodeHere # breakpoint on this line, or just make it `Wait-Debugger`

If there is sufficient demand for it, a command or method to wait for attach can also be considered, but to start off the proposal I'd recommend this as an MVP.

One question that I would suggest be answered in the WG decision is: "What should a remote runspace do for this parameter? Throw? Or always return false?"

Activity

  1. added
    Issue-Enhancement
    Needs-Triage
    WG-Engine
    on Mar 29, 2024
  2. SeeminglyScience commented on Apr 1, 2024

    @SeeminglyScience
    ContributorAuthor

    The Engine WG discussed this and agree

  3. removed
    Needs-Triage
    on Apr 1, 2024
  4. added
    WG-Reviewed
    on Apr 1, 2024
  5. added
    Resolution-No Activity
    on Sep 29, 2024
  6. microsoft-github-policy-service commented on Sep 29, 2024

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  7. added
    KeepOpen
    and removed
    Resolution-No Activity
    on Oct 2, 2024
  8. jborean93 commented on Jul 29, 2025

    @jborean93
    Collaborator

    I've found a need for this for attaching to a pwsh instance in PSES. I've opened #25788 which adds the property specified here but also write a new event which is easy for people to wait on.

  9. microsoft-github-policy-service commented on Oct 7, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey @Patrick Meinecke (@SeeminglyScience), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

  10. removed
    KeepOpen
    on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementWG-EngineWG-Reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions