How to pass a custom function inside a ForEach-Object -Parallel
The solution isn’t quite as straightforward as one would hope: # Sample custom function. function Get-Custom { Param ($A) “[$A]” } # Get the function’s definition *as a string* $funcDef = ${function:Get-Custom}.ToString() “Apple”, “Banana”, “Grape” | ForEach-Object -Parallel { # Define the function inside this thread… ${function:Get-Custom} = $using:funcDef # … and call it. Get-Custom … Read more