What's the easiest way to pass parms to a function in debugging mode

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION 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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 7 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
yobyot
Posts: 40
Last visit: Tue Jun 02, 2020 3:09 pm

What's the easiest way to pass parms to a function in debugging mode

Post by yobyot »

Product, version and build:
64 bit version of product: PowerShell Studio 2016 5.2.127
Operating system: Windows 10 64-bit 10.0.14393 (aka 1607)
PowerShell Version: 5.1.14393

For such an expensive product it bothers me that simple questions like, "How do I get PSS 16 to prompt for params for a function under test?" cannot be answered in the product documentation. I'll bet there's a post somewhere on your blog for this -- but that's inconvenient because the text I search for might be tangental to the post content, making impossible to discover or if I do find something it could well be buried in a long discussion of something else, wasting my time.

I'd like a PDF or, if I have to, something in your very odd "document explorer" that details every aspect of the product -- like normal product documentation does. I'm amazed that you think this product is adequately documented by the blog and the out-of-date files you ship in the distribution software. It's as if PSS 16 is just for those already "in the club" -- the people who know where everything is and how it already works. This must be a real limitation on your adoption rate.

In the ISE, I can write write an advanced function with a mix of mandatory and optional parameters, save it to disk, set a breakpoint then just hit F5 to dot-source it. Then, I can enter the name of the "cmdlet" and provide params and/or be prompted for missing mandatory params. Then I can step through the function as needed.

I can't find an easy way to do that in PSS 16. Sure, I could "run selection in console" but that means losing the the debugger (I think, since the doc -- labelled PSS 15 -- says nothing about using the debugger with advanced functions in the console).

What the doc, such as it is, does say (screenshot attached) is that params are prompted for if there's a Param() block -- but I can't get this to work when debugging an advanced function.

I want to like PSS 16 -- as I go into my second year of subscription and need to use it more -- but the lack of complete, organized, recent doc (the blog is NOT a substitute) is a never-ending frustration. For basic stuff, I find myself back in the ISE -- the very thing I purchased PSS 16 to replace.

So, after the rant, what's the easiest way to debug an advanced function in PSS 16 and get it to prompt for params?
2016-08-22_10-52-15.png
2016-08-22_10-52-15.png (95.86 KiB) Viewed 1508 times
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: What's the easiest way to pass parms to a function in debugging mode

Post by davidc »

I agree with you, the documentation isn’t up to date and needs work. Unfortunately, this is beyond me and the scope of this forum. In any case, I will pass long your grievance.

As for debugging functions:
It sounds like you are placing the function in a file. Since PowerShell Studio doesn't maintain a persistent runspace, all you have to do is call the function with in the script:
  1. function Start-Test
  2. {
  3.  param([Parameter(Mandatory = $true)][string]$param1)
  4.  Write-Host "Start-Test: $param1)
  5. ...
  6. }
  7. #Execute the function to test
  8. Start-Test
If you want to take advantage of PowerShell Studio's script parameter dialog, save the function within a script and remove the outer function declaration:
  1. param([Parameter(Mandatory = $true)][string]$param1)
  2.  Write-Host "Start-Test: $param1)
  3. ...
Now when you run the script, PowerShell Studio will bring up the parameter prompt:
Parameter Prompt.png
Parameter Prompt.png (5.78 KiB) Viewed 1501 times
If you don't specify the mandatory parameter, the host engine will automatically prompt for the parameter value:
Engine Parameter Prompt.png
Engine Parameter Prompt.png (4.31 KiB) Viewed 1501 times
Another advantage of using script parameters, is that you can utilize PowerShell Studio's %DebugParameters% comment:
  1. # %DebugParameters% = -Required 'Test'
This comment tells PowerShell Studio to use the declared arguments when debugging the script.

If you want to force the parameter prompt to appear everytime, use the following comment:
  1. # %ForceParameterPrompt% = Yes
The parameter dialog will be prepopulated with the % DebugParameters% comment arguments:
Prefilled Parameter Prompt.png
Prefilled Parameter Prompt.png (5.41 KiB) Viewed 1501 times
I’m going to add a request, for a “Test this function” feature that will hopefully make this process easier.
David
SAPIEN Technologies, Inc.
This topic is 7 years and 7 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.