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

Start-RSJob Passing a Script w/Script Scope Variables in FunctionFilesToImport #185

Open
adamfortuno opened this issue Jun 8, 2018 · 1 comment

Comments

@adamfortuno
Copy link

On a machine in a distant land, exists a script named thing.ps1 with content:

$script:foo = 'abc'

function f { return $script:foo }

If I attempt to run f from my interactive session, I see "abc" like I'd expect:

image

If I try to run it via Start-RSJob, I see nothing...

Start-RSJob { f } -Name 1 -FunctionFilesToImport $(ls .\thing.ps1).fullname
Receive-RSJob -name 1

image

The value $script:foo in the script passed to Start-RSJob returns as $null.

Can you not use variables in the script scope?

@MVKozlov
Copy link
Contributor

MVKozlov commented Jun 9, 2018

for function f variable $script:foo - like a global variable.
RSJob can not import any variables that used inside functions if it not local.

Btw, it is a bad practice.

as a workaround you can use truly global variables, function parameters or modules (variable defined in a module will be imported with module

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

2 participants