Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help passing variables between jobs #191

Open
hou8182 opened this issue Sep 3, 2018 · 3 comments
Open

Need help passing variables between jobs #191

hou8182 opened this issue Sep 3, 2018 · 3 comments

Comments

@hou8182
Copy link

hou8182 commented Sep 3, 2018

I'm creating a test using a nested multithreaded job. I'm having trouble assuring that the value that I have in $message2 being made available in the nested job. I don't have a problem with the script creating the text file in the directory that I specified, its just that the value turns up blank when I open the text file. By the way, I've also tried adding $using:message2 , but this just threw an error:

Start-RSJob : The value of the using variable '$using:message2' cannot be retrieved because it has not been set in the local session.

$ParentFolder = "C:\users\Family\Desktop\PII Searcher"

$Parentfolder | Start-RSJob -Name {"$($_)"} -Throttle 15 -ScriptBlock{
Param($targetfolder)

$message = "hello"
$global:message2 = "hello2"
$message | Out-File "$targetfolder\message.txt"


     $targetfolder | Start-RSJob -Name {"$($_)"} -Throttle 15 -ScriptBlock{
     Param($targetfolder)

     $message2 | Out-File "$targetfolder\message2.txt"

​     }


}

@MVKozlov
Copy link
Contributor

MVKozlov commented Sep 3, 2018

use -VariablesToImport message,message2 on both Start-RSJob calls
btw, why you need nested jobs ?

p.s. globals is bad :)

@ALuckyGuy
Copy link

@hou8182 I don't think the $targetfolder parameter is working the way you think. Start-RSJob doesn't pass the pipelined objects into the job as a parameter Old versions used to but it changed quite some time ago. Look at this post that explains how parameters work and how you can pass parameters. You can pass message2 into your job but you'll probably want to use the -ArgumentsList parameter.

@MVKozlov
Copy link
Contributor

If the scriptblock have only one parameter then rsjob insert pipelined object into this parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants