Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
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 6 years and 11 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.
So I am converting a utility I wrote for Powershell into a GUI app using Forms. Want my form to be responsive "read all the articles" so I decided to use the job-tracker and integrate my code.
The problem is I call a function from within the JobScript by passing in the function and recreating it
I utilize a single PS file for all my common functions which are contained within the $GlobalFuncDef, my problem is that if I DOT source the $GlobalFuncDef I don't get any of the functions defined within it. How can include these in the $JobScript without having to recreate each one? That would be painful.
You really can't pass a function to a script block.
You are up against one ot the issues that plagues all new programmers; you are trying to over-generalize the code.
The best you can do is to pass the function body to the script block and execute it using "Invoke". You can also use the function body as the script block by extracting it into a new script block:
I wouldn't call it over generalization, I'm just trying not to duplicate code that's already written. Why is it that I can DOT source a file that contains functions and then use the functions within the scope of the script but when you go out of scope in another thread such as a job you can't DOT source that same file? That doesn't really make sense to me.
true so some of the code is not correct then, but still poses the problem. Looks like maybe using the job-tracker might not be what I need to use. thanks for the help.
This topic is 6 years and 11 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.