Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 5 years and 10 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.
$InitializationScript = [scriptblock]::Create(
@"
function Get-Something { ${function:Get-Something} }
function Set-Something { ${function:Set-Something } }
Set-Location $ScriptDirectory # to execute Job with the script or compiled exe directory
"@
)
Is there any better way for background Jobs which are created by JobTracker to have all functions available to use inside Job?
I know, I just wonder if there is a better way that this @""@. Module might be ok but when you are dealing with compiled script to exe i won't help. Maybe Add-JobTracker should importa all variables and functions. Good idea for extension?
$scriptfunctions = {
function global:Test{ 'Hello World!' }
}
$scriptfunctions.Invoke()
Test
Now this can make functions available in the current script (EXE) and be easily passed to a job "InitializationScript".
The key is to add the "global" declaration to the function which allows it to be created in the global scope. The iit script does the "Invoke" under the covers so only the scrip block is required to be passed.
This topic is 5 years and 10 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.