-
Notifications
You must be signed in to change notification settings - Fork 511
Configuration option to debug or run a script without dot sourcing it #4327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's not a bad idea at all, thanks for the suggestion! |
I also would like this. I use AppLocker so Powershell by default runs in Constrained Language mode. But I have certain scripts, and even certain directories set to allowed in AppLocker. So when actually running those scripts, they are actually running in Full Language mode. However, the Powershell extension only runs by dot sourcing, which won't even let it run in the first place, for example:
But when running the script just through a powershell window:
I get:
So it should work, but it can't if it's trying to run by dot sourcing apparently. Without the option to change it, the extension is effectively useless on any device with AppLocker. |
There is a lot of fuss about honoring preference variables in a module. For example, I use DBATools. I have to use the global scope to silence the module. However, without a script scope, I don't have an easy means to set the preferences for my personal use. |
@andyleejordan Is there an ETA for this feature? |
Not currently, sorry. We are swamped with other work right now, but we will get to it eventually! |
I'll add that I would be super happy to take a PR for it! |
Working on getting this in 🙏 |
This issue has been labeled as resolved, please verify the provided fix (or other reason). |
@andyleejordan I'm sure somebody else can test and confirm the fix. |
This issue has been labeled as resolved, please verify the provided fix (or other reason). |
@metablaster no worries! I'll be able to confirm it. Thanks so much for your contribution and sorry it took us so long to address it. |
This issue has been labeled as resolved, please verify the provided fix (or other reason). |
This issue has been labeled as needing fix verification and has not had any activity a week. It has been closed for housekeeping purposes. |
Prerequisites
Summary
There are 3 ways to debug (or run) a script In
VSCode
:Run -> Run Without Debugging
Run -> Start Debugging
launch.json
and start debugging from action bar.In all 3 cases a script will be dot sourced and I don't see a way to instruct debugger to call it rather than dot sourcing it.
I didn't notice this behavior until I stumbled upon a problem which you can see on SO:
"Run without debugging" or "Start debugging" giving different result than running script manually
Here is sample code:
Put it into a script and call it, the result is as expected, "one error", but when you run it with the help of
PS Extension
the result is unexpected because the script isn't meant to be dot sourced.Currently it's impossible to debug or run it and have the result you want.
Debugger should not assume a user whishes to dot source a script.
Proposed Design
I propose an option to let user instruct debugger on how a script is to be executed, for example:
The text was updated successfully, but these errors were encountered: