Run job as a function?

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 6 years and 6 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
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Yes, I do really know that. That's what I also posted in my previous update.
I mentioned before that I do get values in the function (during debugging) so I figured you would ignore the comments.
So to be clear: I am not using the commented code but still then it does not work.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Run job as a function?

Post by jvierra »

Without the code you are using it is impossible to understand the question or propose an answer. You have to think this through and post a code example that is actually being used and an explatnation that we can understand.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Run job as a function?

Post by jvierra »

stevens wrote: Thu Sep 21, 2017 12:44 am I think bottomline is indeed I have to make the script wait for the end of the job. Though I don't know how to make it do that.
The whole purpose of the JobTrakker is to no wait. THe "JobCompleted" script block is called when the job is complete. This is where the data is available if it has not been removed by the "JobUpdate" script block.

Once you understand how this works the rest will become obvious. Go back and read the blog on the Tracker until you understand what it is trying to show you.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Ok, I'll post an example of what I'm trying to do and will look into the jobscript also.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Hope that this code (att.) example makes it clear what I'm trying to do.
Hop you could put me on the way.
Attachments
Retrieve-GroupsAsaJob.psf
(57.47 KiB) Downloaded 106 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Run job as a function?

Post by jvierra »

You didn't follow my instructions. You cannot return a value from that function. It exits before the job even executes.

Use this in the JobCompleted script block.

$textboxresults.Text = = Receive-Job -Job $Job
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Ok, I see. Started all over. However, the $job is empty. Form in att..
Should I then make the $job global via $global:job?
Attachments
Retrieve-GroupsAsaJob-V2.psf
(29.12 KiB) Downloaded 118 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Run job as a function?

Post by jvierra »

How to use jobs in a form with example code: http://tech-comments.blogspot.com/2017/ ... -form.html
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Thanks, but can't you just point out where I'm wrong in my script?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Run job as a function?

Post by stevens »

Ok, I started again from scratch with this form.
This new form receive-job -id 1 is giving my output now, but can't capture it in a variable.
Even with $test = receive-job -id 1 -keep, the $test is empty during debug.
This topic is 6 years and 6 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