1

I can't seem to figure out why the input passed to start-job disappears. I have this code in one script:

$data = "some test string data"
Start-Job -FilePath ".\Tasks.ps1" -InputObject $data

And in the tasks.ps1 script I get a null value for the $input object unless I call it immediately but disappears after doing so:

$input #displays the data
$input #null

I've tried immediately assigning it to another variable ($newvalue = $input) but the value of that variable shows null too.

What am I missing here? How do I retain the input data?

James Santiago
  • 2,883
  • 4
  • 22
  • 29
  • @jamesantiago I have find this start-job question and answer. http://stackoverflow.com/questions/10075943/powershell-pass-variable-to-start-job – Hiten004 Jan 31 '13 at 04:29

1 Answers1

1

Ok, I've found the issue. The $input object is passed as a PilelineReader which I'm assuming is ReadToEnd when called in the job. When I assign the $input to a variable I'm sending the PipeLineReader instead of its value. To get around this I used this:

[string]$newData = $input

This did the trick in preventing a read action happening when accessing the object.

James Santiago
  • 2,883
  • 4
  • 22
  • 29