function doStuff { param( [string] $Item, [string] $Value = 'default' ) $htDoStuff.($Item) = $Value } function Invoke-DoStuff { $stringFuncDoStuff = "${function:doStuff}" $htDoStuff = [System.Collections.Hashtable]::Synchronized((New-Object System.Collections.Hashtable)) #@{} $array = @('first', 'second') # ForEach-Object -Parallel $array | ForEach-Object -Parallel { $function:doStuff = $using:stringFuncDoStuff $htDoStuff = $using:htDoStuff doStuff -Item $PSItem } $htDoStuff } function Invoke-ModuleDoStuff { $stringFuncDoStuff = "${function:doStuff}" $array = @('first', 'second') # ForEach-Object -Parallel $array | ForEach-Object -Parallel { $function:doStuff = $using:stringFuncDoStuff $htDoStuff = $using:moduleHtDoStuff doStuff -Item $PSItem -Value $(Get-Date).Ticks } $moduleHtDoStuff } $moduleHtDoStuff = [System.Collections.Hashtable]::Synchronized((New-Object System.Collections.Hashtable)) #@{} Export-ModuleMember -Function 'Invoke-DoStuff', 'Invoke-ModuleDoStuff'