Conversation
Move Add-Member calls for Enabled and EnabledOn outside the inner foreach-ca loop so that both properties are computed across all enrollment services before being assigned to the template object. Previously, Add-Member was called on every CA iteration, writing intermediate (potentially incomplete) state to the template object and performing O(n_cas) unnecessary property assignments per template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes how the Enabled / EnabledOn properties are assigned in Set-AdditionalTemplateProperty by ensuring they’re computed across all enrollment services first, then attached to the template object once per template (instead of once per CA iteration). This improves both correctness (no intermediate/partial state written mid-loop) and performance (fewer Add-Member calls).
Changes:
- Move
Add-MemberforEnabledandEnabledOnoutside the inner CAforeachloop so assignment happens once per template. - Update the generated
Invoke-Locksmith.ps1artifact to mirror the source change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Private/Set-AdditionalTemplateProperty.ps1 | Assigns Enabled/EnabledOn after evaluating all CAs for a template (avoids per-CA intermediate writes). |
| Invoke-Locksmith.ps1 | Updates the generated script artifact to match the fixed assignment timing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Copilot review analysis (automated): The GitHub Copilot automatic review (4234840282) reviewed all 2 changed files and generated no inline comments or suggestions. The review correctly characterizes the fix: \Add-Member\ calls moved outside the inner CA loop so \Enabled/\EnabledOn\ are assigned once per template after all enrollment services are evaluated. Classification: ✅ No actionable items — review confirms the implementation is correct as-is. Nothing to implement or disregard. No follow-up changes needed from this review cycle. |
Summary
Move
Add-Membercalls forEnabledandEnabledOnoutside the innerforeach ($ca ...)loop inSet-AdditionalTemplateProperty, so both properties are computed across all enrollment services before being assigned to the template object.Problem
In the original code,
Add-Memberwas called on every iteration of the CA loop — once per enrollment service per template — writing intermediate state to the template object before all CAs had been checked:This causes two issues:
Add-Memberis invoked O(n_cas) times per template instead of once.Enabled/EnabledOnconcurrently (or after an early-exit scenario) could see incorrect state.Fix
Move both
Add-Membercalls to after the loop completes:Files Changed
Private/Set-AdditionalTemplateProperty.ps1— source fixInvoke-Locksmith.ps1— generated artifact updated in parity with the build convention (copied fromArtefacts/Script/byBuild/Build-Module.ps1)Validation