Urgent!! How to use invoke-expression functionName when I click Button-Start Job in

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 2 years and 9 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.
Locked
HWLDOME
Posts: 11
Last visit: Thu Jun 15, 2023 10:13 pm
Has voted: 1 time

Urgent!! How to use invoke-expression functionName when I click Button-Start Job in

Post by HWLDOME »

I add a button-Start Job to a form and wish to run a function A defined in Global.ps1 when I click this button. I directly write $result = Invoke-expression A in JobScript, but it seems does not work. Please refer to the sample code here. Thank you very much.

$paramAddJobTracker = @{
Name = 'JobName'
JobScript = {
#--------------------------------------------------

Param ()
$result = Invoke-Expression A
return $result
#--------------------------------------------------
}
ArgumentList = $null
CompletedScript = {
Param ([System.Management.Automation.Job]$Job)
$result = Receive-Job -Job $Job

#Enable the Button
$buttonStartJob.ImageIndex = -1
$buttonStartJob.Enabled = $true
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Urgent!! How to use invoke-expression functionName when I click Button-Start Job in

Post by jvierra »

You cannot call a function that is not in an available module or included in the job script.
This topic is 2 years and 9 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.
Locked