PowerShell Studio: Reuse PowerShell Process

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
This topic is 6 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

When debugging a script, PS Studio starts a new PowerShell process each time debugging starts. Is it possible to reuse the same PowerShell process, like PowerShell ISE?

Product, version and build: PowerShell Studio 2017 5.4.144
32 or 64 bit version of product: 64
Operating system:
32 or 64 bit OS: 64
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: PowerShell Studio: Reuse PowerShell Process

Post by Alexander Riedel »

For just running the script you can run it in the embedded shell. That will persist after the script is finished.
For debugging, no. It is not advisable to re-use a runspace for debugging repeatedly, as the runspace would be contaminated by the previous execution of the script. For debugging you need reproducible results.
Is there a particular reason you ask for this?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

Re: PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

Thanks for the clarification.

When developing a script, I often debug the script after incremental changes to test new code or to inspect variables. E.g., I hit a breakpoint, and notice that I need to modify the code. I can terminate the debugging session, make minor adjustments, and initiate a new debugging session.

I'm just trying out PS Studio, but from my initial experiences, what I can accomplish in 1-2 minutes with ISE takes 10+ with PS Studio. The overall development experience is much better, but with the specific workflow I outlined, ISE is much more usable.

It would be nice if there was an option or separate command that controls whether a runspace can be re-used. Or, similar to ISE, breakpoints could be enabled for scripts executed using the embedded console.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: PowerShell Studio: Reuse PowerShell Process

Post by Alexander Riedel »

The process is pretty much the same, you stop debugging, make adjustments and start again. I don't really see where this would take longer, except for maybe powershell engine startup. Re-using the runspace would not result in anything faster, it would just make sure that you miss uninitialized variables and other conditions caused by runspace contamination. At this point I usually point out that no other language would ever allow you to re-run a process in a contaminated environment (that I am aware off).

At any rate, the ISE is something you have. There is no mutual exclusivity here and I know of a few cases where using the ISE is beneficial to locating particular problems. In general there never is a catch-all tool and we always encourage everyone to have a wide variety of tools at their disposal and be familiar with all of them.

So if your experience is that for certain cases the ISE gives you faster results, use it. We won't judge :D
PowerShell Studio was not meant to replace the ISE, since that is something you already have.

I hope that helps.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

Re: PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

Yes, your explanation helps, thank you.

I should have been specific. The reason for the delay is precisely what you mentioned – The PS engine startup time. It generally takes several seconds for PowerShell to startup with the default terminal and ISE. However, with ISE it only occurs once so it's a bit easier to manage.

Is there anything I can do to speedup the PowerShell engine startup when debugging with PS Studio?
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: PowerShell Studio: Reuse PowerShell Process

Post by Alexander Riedel »

It shouldn't really take all that long. Can you give me a number of how long that takes for you? Is this a VM?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

Re: PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

I manually timed a few sessions:

Steps to Reproduce:
  1. Set a breakpoint on the first line of a script
  2. Debug the script
  3. Wait for breakpoint to be hit
  4. Press CTRL+F5, then F5 to start a new debugging session
  5. Wait for breakpoint to be hit
Result:
  • On average, 12-15s elapse between Steps 4 & 5
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

Re: PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

This is a physical machine.

Specs:
Windows 10 Pro 64-bit
Intel Core i7 6600U @ 2.50GHz
16.0GB Dual-Channel DDR3 @ 797MHz (12-15-15-34)
SSD
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: PowerShell Studio: Reuse PowerShell Process

Post by Alexander Riedel »

I'll give that QA to see what they can find out about this. Thanks for sending the data.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
aip1000
Posts: 8
Last visit: Sun Oct 15, 2017 5:19 pm

Re: PowerShell Studio: Reuse PowerShell Process

Post by aip1000 »

My pleasure. Thanks for your assistance.
This topic is 6 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.