Experimental PowerShell discover extension#1071
Experimental PowerShell discover extension#1071Gijsreyn wants to merge 47 commits intoPowerShell:mainfrom
Conversation
|
With PR #1025 around, it might be worthwhile to rename the directories. |
623d593 to
5b7502f
Compare
5b7502f to
991f7ce
Compare
…jsreyn/operation-methods into implement-powershell-discover
6337045 to
f15195a
Compare
michaeltlombardi
left a comment
There was a problem hiding this comment.
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.
|
…jsreyn/operation-methods into implement-powershell-discover
|
@SteveL-MSFT - by any chance, if you have time to review this one, I would appreciate it. |
…into implement-powershell-discover
|
@SteveL-MSFT - caching added. Took a couple of rounds because of returning nothing. Added this to the docs after discussing with Mikey. |
…jsreyn/operation-methods into implement-powershell-discover
…github.com/Gijsreyn/operation-methods into implement-powershell-discover
There was a problem hiding this comment.
Pull request overview
Adds an experimental PowerShell discover extension to enable DSC to discover resource/extension manifests shipped inside PowerShell 7 modules (via PSModulePath), aiming to reduce overhead versus Get-ChildItem by using .NET enumeration with parallelism and a disk cache.
Changes:
- Introduces a new
Microsoft.PowerShell/Discoverextension manifest and apwsh-based discover script. - Adds Pester tests validating cache creation/usage/invalidation and discovery output.
- Updates extension discovery tests and clarifies discover stdout documentation (including “no output when nothing is found”).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| extensions/powershell/powershell.dsc.extension.json | Registers the new PowerShell discover extension (pwsh entrypoint). |
| extensions/powershell/powershell.discover.ps1 | Implements module-path scanning + caching for discovered manifests. |
| extensions/powershell/powershell.discover.tests.ps1 | Adds tests for cache and discovery behavior of the PowerShell discover script. |
| extensions/powershell/copy_files.txt | Ensures the new script/manifest are packaged with the extension. |
| dsc/tests/dsc_extension_discover.tests.ps1 | Expands extension list expectations to include the new PowerShell discover extension. |
| docs/reference/schemas/extension/stdout/discover.md | Updates/clarifies discover stdout schema guidance, including empty-output semantics. |
Comments suppressed due to low confidence (1)
dsc/tests/dsc_extension_discover.tests.ps1:66
- The new
$expectedExtensionsloop isn’t closed before the old$IsWindowsassertions start, so the legacy assertions are now nested inside theforeachand will run multiple times (and the old expected counts/types are no longer correct). Remove the old block (or move it outside) and ensure theforeachblock is properly closed.
$out.Count | Should -Be $expectedExtensions.Count -Because ($out | Out-String)
foreach ($expected in $expectedExtensions) {
$extension = $out | Where-Object { $_.type -eq $expected.type }
$extension | Should -Not -BeNullOrEmpty -Because "Extension $($expected.type) should exist"
$extension.version | Should -BeExactly $expected.version
$extension.capabilities | Should -BeExactly $expected.capabilities
$extension.manifest | Should -Not -BeNullOrEmpty
if ($IsWindows) {
$out.Count | Should -Be 2 -Because ($out | Out-String)
$out[0].type | Should -Be 'Microsoft.Windows.Appx/Discover'
$out[0].version | Should -Be '0.1.0'
$out[0].capabilities | Should -BeExactly @('discover')
$out[0].manifest | Should -Not -BeNullOrEmpty
$out[1].type | Should -BeExactly 'Test/Discover'
$out[1].version | Should -BeExactly '0.1.0'
$out[1].capabilities | Should -BeExactly @('discover')
$out[1].manifest | Should -Not -BeNullOrEmpty
} else {
$out.Count | Should -Be 1 -Because ($out | Out-String)
$out[0].type | Should -BeExactly 'Test/Discover'
$out[0].version | Should -BeExactly '0.1.0'
$out[0].capabilities | Should -BeExactly @('discover')
$out[0].manifest | Should -Not -BeNullOrEmpty
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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