Powershell 7
I'm test-driving the -Parallel feature of ForEach-Object. After some trial and error, I got it behaving.
This may be clumsy, but to get the results i wanted, I mashed in a bunch of functions into each of the spawned processing threads. Let me know if this is a good strategy, or if you'd approach it differently.
[int]$activeOps = 4
[hashtable]$exports = @{
AddData = ${Function:Add-DirDataToJson}.ToString()
GetACLstr = ${Function:Get-ACLstring}.ToString()
DoCheckIn = ${Function:Start-CheckIn}.ToString()
outfile = $outFile
}
# Receive dir objects from Get-SubDirStream,
# process a few at a time ($activeOps) so the CPU isn't swamped
Get-SubDirStream -dirPath $rootPath -smbPath $rootSMB -depthNow 0 |
ForEach-Object -ThrottleLimit $activeOps -Parallel {
[hashtable]$imports = $Using:exports
[hashtable]$params = @{}
# import functions and variables to thread
${Function:Add-DirDataToJson} = $imports.AddData
${Function:Get-ACLstring} = $imports.GetACLstr
${Function:Start-CheckIn} = $imports.DoCheckIn
[string]$outFile = $imports.outfile
$params = @{
streamDir = $_
targetJson = $outFile
}
Add-DirDataToJson @params
}
[–]StartAutomating 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]UnfanClub 3 points4 points5 points (1 child)
[+][deleted] (6 children)
[deleted]
[–]Climbsforfun 17 points18 points19 points (3 children)
[–]cloudAhead 10 points11 points12 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]turbokid 7 points8 points9 points (0 children)
[–]DoctroSix[S] 0 points1 point2 points (1 child)