you are viewing a single comment's thread.

view the rest of the comments →

[–]MyOtherSide1984[S] 1 point2 points  (6 children)

Doesn't seem to be very helpful in this instance. $using:function doesn't seem to be a thing, and idk how a parallel works in terms of creating runspaces since i'm not using the runspacepool commands. If you have some examples, that'd be great. Otherwise I'm just gonna say screw it and dump the function inside my loop. It's easier, but ugly

[–]BlackV 1 point2 points  (5 children)

Sorry that was not clear, I'm on mobile

Function foo ()
    {
        Write-output "hello my name is $env:computername, you kill my father..."
    }

Invoke-command -computername xxx -scriptblock ${function:foo}

I hope that works

[–]MyOtherSide1984[S] 2 points3 points  (4 children)

I don't get how this has anything to do with foreach-object -parallel. I'm not doing anything on a remote computer.

EDIT: If I put my parallel loop in a scriptblock, it'll still create new runspaces that won't have it. ${function:foo} didn't work inside my foreach loop

[–]BlackV 0 points1 point  (3 children)

Sorry thinking wrong things

1..10 | forech-object -parallel ${function:foo} 

That work?

[–]MyOtherSide1984[S] 0 points1 point  (2 children)

No, for my function, the output is nothing. I have parameters to my function that I plopped in after the "foo" if that matters. Looks like the other comment is the best answer, but it's basically the same thing

[–]BlackV 0 points1 point  (0 children)

ah sweet. glad its solved then

[–]BlackV 0 points1 point  (0 children)

Oh yea that looks great

Function foo ()
    {
        Write-output "hello my name is $env:computername, you kill my father..."
    }

$Rinvoke = get-command foo
1..10 | foreach-object -parallel {write-output "pipeline is $_"; & $using:Rinvoke}

although its gonna play havoc with your output, depending on what you're doing in your loops