Page 1 of 2

returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 7:36 am
by noescape
Hi,

I'm struggling with returning of an object from a finished job from inside the jobtracker framework.

The -jobscript{} block processes and returns some data that are stored in a custom object, then I pass the data to -completedscript{} block with

Code: Select all

return $data
at the end of the jobscript.
In the

Code: Select all

-completedscript{}
block I use receive-job to retrieve the data:

Code: Select all

-CompletedScript {
Param ($Job)
$data = @{ }
$data = Receive-Job -Job $Job
}
That's all fine, the data is stored in $data variable but gets lost just when the -completedscript{} block finishes and leaves the jobtracker function. My question is, how do I store / pass the data from the block so it doesn't get lost when the jobtracker function ends? I was thinking that it has something to do with the Update-Jobtracker function that calls the scriptblock via invoke-command. Can you please help / guide me to better understanding of this framework? I read all about 'creating responsive forms' but couldn't find anything helpful.

Thanks in advance,

Tom

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 8:27 am
by jvierra
Where do you want t "store" the data?

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 8:42 am
by dan.potter
Easiest way is a psobject. Merely assigning variables does not constitute data. You can see the difference in the shell. get-job will show if the job has data or not.

I posted code yesterday on jobtracker in the PSGUI topic.

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 8:54 am
by jvierra
Dan - the likelihood that the result is a PsObject already...

Just creating an object does not "store" anything.

We could output to a file. We could export to a CSV file. We could display in a textbox.
What does "store" mean? As used here, "store" is an ambiguous term and not a technical term.

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 9:09 am
by noescape
I want to have access to the data outside of the jobtracker function but not output it to a file. Basically what I am trying to achieve is having a Job#1 return some data and save it outside of the job when it finishes. Then I need to run Job#2 which will also create very similar data and after it finishes I want to compare those results and out-file them to a text file.

The way I tried to achieve that was creating an object inside the scriptblock itself, then I can return it to "completed script" block but I'm not able to get it "outside" of the function after that. Think it's because the "completed script" gets processed in the "Update-Jobtracker" function with Invoke-Command,but the output doesn't get saved so that I could see it from outside after that. I don't want to mess with the jobtracker framework so maybe there is another approach I could use.

Tom

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 9:18 am
by noescape
I wanted to provide a code I'm working with but anti-spam is blocking me from posting it (URL links are not allowed - there aren't any links in it tho).

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 9:35 am
by jvierra
noescape wrote:I wanted to provide a code I'm working with but anti-spam is blocking me from posting it (URL links are not allowed - there aren't any links in it tho).
To post links you need to use the add attachments or use the full editor and not the "quick" edit box.

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 9:41 am
by jvierra
noescape wrote:I want to have access to the data outside of the jobtracker function but not output it to a file.
Tom
You need to save the data to a variable that has a scope that makes it available.

$script:data=Receive-Job $job

help scope

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 9:47 am
by noescape
Thanks for quick help, I already tried that though and it still got thrown out of the window as soon as the completedscript block ended. I will test again tomorrow and let you know.

BTW I didn't add any link to the reply, it's a false anti-spam bug on your forum. I added a powershell code and enclosed it in codebox. I had to remove the whole code to get past that.

Tom

Re: returning of an object from jobtracker completedscript block

Posted: Wed Nov 25, 2015 11:08 am
by noescape
The script scope works like you said, so thank you. The problem was that I pre-defined the variable somewhere else without setting the scope and then I was assigning the data to that variable setting the script scope over there instead (I guess it doesn't work that way).
Anyway, thanks for the fast aid, It was getting a little bit frustrating.

Regards,

Tom