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.
Description
azd updatefails with:Root Cause
When
azd updateinvokes the install script, the exec package wraps all Windows commands incmd.exe /c(command_runner.go:99). The call chain is:PowerShell 5.1 normally overrides the inherited
PSModulePathwhen its parent is another PowerShell process. However, thecmd.exeintermediary prevents this override. PS5.1 seescmd.exeas its parent, notpwsh, so it keeps the inheritedPSModulePathwhich includes PS7 Core-edition module paths.PS7's
Microsoft.PowerShell.Securitymodule (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
Fix
Reset
PSModulePathto Windows PowerShell 5.1 defaults inbuildInstallScriptArgs()before invoking the install script.