Skip to content

azd update fails with CouldNotAutoloadMatchingModule when parent shell is PowerShell 7 #7702

@hemarina

Description

@hemarina

Description

azd update fails with:

The 'Get-AuthenticodeSignature' command was found in the module
'Microsoft.PowerShell.Security', but the module could not be loaded.
FullyQualifiedErrorId: CouldNotAutoloadMatchingModule

Root Cause

When azd update invokes the install script, the exec package wraps all Windows commands in cmd.exe /c (command_runner.go:99). The call chain is:

pwsh (PS7) -> azd.exe -> cmd.exe /c powershell.exe 5.1

PowerShell 5.1 normally overrides the inherited PSModulePath when its parent is another PowerShell process. However, the cmd.exe intermediary prevents this override. PS5.1 sees cmd.exe as its parent, not pwsh, so it keeps the inherited PSModulePath which includes PS7 Core-edition module paths.

PS7's Microsoft.PowerShell.Security module (CompatiblePSEditions: Core) appears before PS5.1's version (CompatiblePSEditions: Desktop) in the search path. PS5.1 attempts to load the Core-edition module, which fails with TypeData conflicts.

Affected Environments

  • VSCode integrated terminal (default shell: pwsh/PowerShell 7)
  • Windows Terminal (default shell: pwsh/PowerShell 7)
  • Any terminal where the parent shell is PowerShell 7+

Fix

Reset PSModulePath to Windows PowerShell 5.1 defaults in buildInstallScriptArgs() before invoking the install script.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions