Extracting a variable from within a scriptblock

This topic contains 4 replies, has 2 voices, and was last updated by  Max Kozlov 1 year, 7 months ago.

  • Author
  • #58421

    Recco Bucceri

    Hey all,

    I am performing a start-job -scriptblock{} and need to extract the variable that i create inside the script block. I was so sure that this could be done, but for the life of me, cannot work it out...

    So inside the script block i build an array using "if" and "else". After the job is run, i am attempting a receive-job -keep and trying to see how the information gets kept. But it seems the array i create doesnt stay stored in the job.

    Any ideas?

  • #58423

    Max Kozlov

    send your array to output and capture it outside

    start-job { $jobarray = 1..100; $jobarray }
    #simulate work
    start-sleep -sec 10
    $array = get-job | receive-job
    • #58513

      Recco Bucceri

      That is awesome!

      I am about to test this and i will report back, appreciate the help.

  • #58591

    Recco Bucceri

    Ok so its not working. I suspect i have been staring at this piece of code for to long and need a fresh pair of eyes.

    So basically what i am trying to achieve is building a tenant report that will be merged with a on-premise (AD) report in powerBI. I currently have around 90 000 users in my tenant and when i start trying to pull the report, i eventually start getting I/O operation timeout errors. When i did a little research, it seems the moment you go over 50 000 objects, this error can start occuring. I tested just pulling UPN and Immutable ID, and this worked fine. So i figured that if i can use this info and instead I create a start-job with 1000 users at a time, i could circumvent this problem. So in each job i successfully create a new pssession, but is all that seems to run. My info gathering doesnt seem to kick off.

    Anything you guys can suggest?

  • #58592

    Max Kozlov

    and what line of your code send your $report array to output ?

    anyway, you can instead of

    $Report = @() 
                                 $Report += New-Object psobject -Property @{ 

    just write

                                 New-Object psobject -Property @{ 

    and send all of your objects to output stream

You must be logged in to reply to this topic.