Skip to content

win_psDscAdapter.psm1: Retry to import module again if CommandNotFoundException is thrown#1575

Open
ricmestre wants to merge 3 commits into
PowerShell:mainfrom
ricmestre:fixcmdnotfoundexception
Open

win_psDscAdapter.psm1: Retry to import module again if CommandNotFoundException is thrown#1575
ricmestre wants to merge 3 commits into
PowerShell:mainfrom
ricmestre:fixcmdnotfoundexception

Conversation

@ricmestre

Copy link
Copy Markdown

PR Summary

This PR fixes an issue if trying to import a module and it throws a CommandNotFoundException, e.g. when the module contains a ScriptsToProcess directive.

PR Context

When trying to enumerate the resources from module Microsoft365Dsc, which uses the adapter Microsoft.Windows/WindowsPowerShell, it throws an error because this module contains a ScriptsToProcess directive and the function GetTypeInstanceFromModule, from win_psDscAdapter.psm1, cannot cope with it because a CommandNotFoundException will be thrown . This PR fixes this by retrying to import the module once again a second time, only if the exception thrown is CommandNotFoundException, which will work as advised by @Gijsreyn.

This should fix the issue #1574 I raised earlier.

Copilot AI review requested due to automatic review settings June 14, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds error handling around module import/type resolution in the PowerShell DSC adapter to reduce failures when resolving a type from a module.

Changes:

  • Wrapped the Import-Module + module-scoped execution in a try/catch.
  • Added special-case retry logic when a CommandNotFoundException is encountered.

Comment thread adapters/powershell/psDscAdapter/win_psDscAdapter.psm1 Outdated
Comment thread adapters/powershell/psDscAdapter/win_psDscAdapter.psm1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants