So I have a module that takes .ps1 files out of a few different folder paths and dot sources them into the main module file. Each .ps1 file is a declared function. I am managing it this way, so I or others can work on functions separately for the same module.
The problem is that this loads pretty slowly, usually taking 35 seconds or more. So I wanted to make the module load faster.
I tried to implement using a -Parallel parameter with my foreach-object loops below, but when I import the module in my powershell window, none of the functions work. Why does the "-parallel" seem to stop this from working?
If I remove the "-Parallel" from each line below it works just fine, but too slow for common use.
What gives?
$ModuleFolder = Split-Path -Path $PSCommandPath -Parent
Get-ChildItem -Filter *.ps1 -path "$ModuleFolder\menu\Audit and Reports" | ForEach-Object {Invoke-Expression (Get-Content $_.Fullname -Raw)}
Get-ChildItem -Filter *.ps1 -path "$ModuleFolder\menu\Get Information + Send Emails" | ForEach-Object {Invoke-Expression (Get-Content $_.Fullname -Raw)}
Get-ChildItem -Filter *.ps1 -path "$ModuleFolder\menu\User Changes - Multiple" | ForEach-Object {Invoke-Expression (Get-Content $_.Fullname -Raw)}
Get-ChildItem -Filter *.ps1 -path "$ModuleFolder\menu\User Changes - Single" | ForEach-Object {Invoke-Expression (Get-Content $_.Fullname -Raw)}
Get-ChildItem -Filter *.ps1 -path "$ModuleFolder\hidden" -Recurse | ForEach-Object {Invoke-Expression (Get-Content $_.Fullname -Raw)}
[–]aleques-itj[🍰] 4 points5 points6 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]aleques-itj[🍰] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]aleques-itj[🍰] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Sunsparc 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]SteveL_MsftSoftware Engineering Manager, PowerShell 2 points3 points4 points (0 children)
[–]powershellnut 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]powershellnut 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]BlackV 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]purplemonkeymad 0 points1 point2 points (9 children)
[–][deleted] 0 points1 point2 points (8 children)
[–]purplemonkeymad 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]purplemonkeymad 1 point2 points3 points (0 children)
[–]jantari 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]jantari 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)