My question is, how do I run "one of my own" functions from the JobScript script block?
Below is a simple example of what I am trying to achieve (in my real example my function does a lot more):
### global.ps1 ### function Get-ScriptDirectory { ... } ### MainForm.psf ### $button_click = { Add-JobTracker -Name "Job1" -JobScript { Get-ScriptDirectory } -CompletedScript { /* Receive-Job and update a text box*/ } }However, when I run this I get an exception saying: "The term 'Get-ScriptDirectory' is not recognized as the name of a cmdlet, function, script file or operable program."
It seems that my global functions are not in scope in the JobScript script block. However, if I call the Get-ScriptDirectory function directly from the CompletedScript, it works just fine. I tried passing my function as a parameter to the JobScript, but that still gave me the exception. If I pass a JobScript with either {ls function:} or {get-command *get-script*}, I get the function/command lists, by they only contain the standard PowerShell session functions/commands.
So how to I get my functions to be in-scope in the JobScript?
Note: I've found another post on this forum regarding the same issue, but no actual solution was found here: viewtopic.php?f=21&t=9384&p=50858&hilit ... ion#p50858
Any input will be much appreciated!
Kristian