Experimental PowerShell discover extension
PR Summary
Implements an optimized approach to discovering PowerShell resources using .NET with parallel processing and direct result synchronization.
The previous approach using Get-ChildItem had unnecessary object overhead and required post-processing with Where-Object. The same is implied when using a thread-safe collection (ConcurrentBag), which adds unnecessary complexity.
PR Context
Fix #913
With PR #1025 around, it might be worthwhile to rename the directories.
A few questions and requests:
- Do I correctly understand that this extension only for resources implemented in PowerShell and excluding Windows PowerShell? If so, do we need a second extension for discovering those resources, or can we handle that in this one? I'm not sure I see an immediate reason for why we can't handle both here, given the manifest has to indicate whether the resource is invoked with
powershellorpwsh.- Can we slightly restructure this script to define (currently empty)
paramblock and put the implementation into theprocessblock? That can help with organization and testing later on.- The current implementation can't run in Windows PowerShell, I think, given the use of
ForEach-Object -Parallel- but we can still discover resources in Windows PowerShell modules.
- The one currently written is only compatible with PowerShell 7+ because of the
[System.IO.EnumerationOptions]. We might be able to rewrite it, but as you also mentioned (from point 3), theForeach-Object -Parallelis not implemented. It would be best to create a second extension for it with different logic. - Sure, I'll implement this change. Thanks for the comment!
- Answered in point 1.
The WG discussed this and agree to not have WinPS support initially until there is a customer need
@SteveL-MSFT - by any chance, if you have time to review this one, I would appreciate it.
@SteveL-MSFT - caching added. Took a couple of rounds because of returning nothing. Added this to the docs after discussing with Mikey.