question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell SDK should support easier invocation of PowerShell that is hidden from the debugger and that ignores `$PSDefaultParameterValues` and `*Preference` variables

See original GitHub issue

Summary of the new feature/enhancement

When people build non-module tools that use the PowerShell SDK, they ultimately need to invoke some PowerShell commands. For tools are meant to function as a black box, the PowerShell commands that the tool invokes…

  1. …should be hidden from the PowerShell debugger (so that breakpoints do not trigger on tool internals);
  2. …should not pick up on user parameter preferences defined in $PSDefaultParameterValues;
  3. …should not pick up on user invocation preferences defined in $*Preference variables;

This needs to be very, very easy so that tools can work as they were designed, without changes in behavior because of user preferences, and without the PowerShell debugger tripping on non-user code that is meant to be internal.

For a related discussion that highlights what tool makers need to think about in detail, see this comment in issue #2121 of PowerShell\vscode-powershell. That discussion also shows the scaffolding that is required to do something that should be very simple and supported in the SDK via a few flags.

Proposed technical implementation details (optional)

Any public interface that allows users to build PowerShell commands piecemeal (i.e. AddCommand, AddParameter, AddScript, AddArgument, etc.) and then invoke them needs to support invocation options that:

  • hide the command(s) from the debugger;
  • ignore $PSDefaultParameterValues;
  • automatically apply default values for any common parameters that are not explicitly used.

~That’s not very specific, so obviously more investigation would be necessary to identify where to create these options so that they can be used via public interfaces, and where the options would need to be plumbed through the PowerShell runtime so that toolmakers get the results they expect.~

Update copied from discussion below:

To achieve this goal, S.M.A.PSInvocationSettings will be extended with a DebuggerHidden property, which would ensure the commands were hidden from the debugger, and a IgnorePreferenceVariables property, which would ignore $PSDefaultParameterValues and $*Preference variables. Programmers using the SDK can pass their PSInvocationSettings instance into S.M.A.PowerShell.Invoke, and with the new settings properly plumbed through the runtime, they won’t have to worry about user preferences impacting internal APIs.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KirkMunrocommented, Aug 18, 2019

ISE seemed to do OK. It managed, manipulated state and debugged multiple runspaces both local and remote.

ISE isn’t that advanced as far as IDEs go, and it is still susceptible to internal behavior that can be unintentionally manipulated by use of $PSDefaultParameterValues, breakpoints, and $*Preference variables. PowerShell itself suffers the same problem. It just doesn’t show up that often, but regardless of the frequency, SDK users should be able to use the runtime in a way that internals are kept internal.

1reaction
BrucePaycommented, Aug 10, 2019

@KirkMunro Why not just use a separate runspace.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Preference Variables - PowerShell
Determines how PowerShell responds to debugging messages generated by a script, cmdlet or provider, or by a Write-Debug command at the command ...
Read more >
How to Use $PSDefaultParameterValues - PowerShell ...
Summary. The $PSDefaultParameterValues automatic variable is a great tool to help you specify specific values for cmdlet parameters. You can ...
Read more >
about Redirection - PowerShell
Explains how to redirect output from PowerShell to text files.
Read more >
about CommonParameters - PowerShell
Several common parameters override system defaults or preferences that you set using the PowerShell preference variables.
Read more >
about Scopes - PowerShell
Explains the concept of scope in PowerShell and shows how to set and change the scope of elements.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found