I have a script that pulls ACLs for a given set of paths using the NTFSsecurity Module. I have attempted to speed this up using Invoke-Parallel and I’m seeing some odd behavior. I’m testing with the windows directory on my laptop which is about ~150k directories. The first 3,000 threads or so go very quickly but after that it seems to drag. Local resources aren’t an issue as I have memory and CPU to spare while this is running. I’m on Windows 10 creators update with PS 5.1. The original code measures at 3min 8 seconds for the same set of paths. While the parallel code is pushing 30min. My suspicion is this is due to needing to import the module every time so I’m not sure if there is a way to improve this. I opted to import the module in the script block vs -ImportModules so as not to import anything unnecessary.
$Paths | Get-NTFSAccess| Select-Object Account, AccessRights, Fullname
Invoke-Parallel -InputObject $Paths -Throttle 200 -ScriptBlock{ Import-Module ntfssecurity $_ | Get-NTFSAccess| Select-Object Account, AccessRights, Fullname }
Edit: I have tried the following and gotten only a minor performance gain. Even with only 10,000 paths it takes 4min 14sec vs 20sec without invoke-parallel
Invoke-Parallel -InputObject $Paths -Throttle 200 -RunspaceTimeout 2 -NoCloseOnTimeout -ScriptBlock{ Import-Module ntfssecurity $_ | Get-NTFSAccess| Select-Object Account, AccessRights, Fullname }