Support Forums

returning of an object from jobtracker completedscript block

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

returning of an object from jobtracker completedscript block

Postby noescape » Wed Nov 25, 2015 7:36 am

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
return $data
at the end of the jobscript.
In the
-completedscript{}
block I use receive-job to retrieve the data:

-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
User avatar
jvierra
Posts: 10021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: returning of an object from jobtracker completedscript block

Postby jvierra » Wed Nov 25, 2015 8:27 am

Where do you want t "store" the data?
User avatar
dan.potter
Posts: 661
Joined: Wed Oct 08, 2014 6:02 am

Re: returning of an object from jobtracker completedscript block

Postby dan.potter » Wed Nov 25, 2015 8:42 am

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.
User avatar
jvierra
Posts: 10021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: returning of an object from jobtracker completedscript block

Postby jvierra » Wed Nov 25, 2015 8:54 am

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.
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

Re: returning of an object from jobtracker completedscript block

Postby noescape » Wed Nov 25, 2015 9:09 am

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
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

Re: returning of an object from jobtracker completedscript block

Postby noescape » Wed Nov 25, 2015 9:18 am

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).
User avatar
jvierra
Posts: 10021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: returning of an object from jobtracker completedscript block

Postby jvierra » Wed Nov 25, 2015 9:35 am

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.
User avatar
jvierra
Posts: 10021
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: returning of an object from jobtracker completedscript block

Postby jvierra » Wed Nov 25, 2015 9:41 am

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
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

Re: returning of an object from jobtracker completedscript block

Postby noescape » Wed Nov 25, 2015 9:47 am

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
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

Re: returning of an object from jobtracker completedscript block

Postby noescape » Wed Nov 25, 2015 11:08 am

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

Return to “Windows PowerShell”

Who is online

Users browsing this forum: No registered users and 2 guests