VS Code PowerShell extension shadows newer PSScriptAnalyzer versions, breaking Invoke‑Formatter #5632
Description
Prerequisites
- I have written a descriptive issue title.
- I have searched all open and closed issues to ensure it has not already been reported.
- I have read the troubleshooting guide.
- I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
- I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
- If this is a security issue, I have read the security issue reporting guidance.
Summary
Body
Environment
VS Code PowerShell extension: ms-vscode.powershell-2025.4.0
PowerShell version: 7.6.6
OS: Windows 11
User-installed PSScriptAnalyzer: 1.25.0
VS Code bundled PSScriptAnalyzer: 1.24.0
Summary
The VS Code PowerShell extension loads its bundled copy of PSScriptAnalyzer 1.24.0, which shadows the user-installed PSScriptAnalyzer 1.25.0. As a result, the PowerShell session inside VS Code cannot access Invoke-Formatter, even though the correct module version is installed and visible in $PSModulePath.
This breaks script formatting functionality inside VS Code.
Expected Behavior
VS Code should:
Prefer the user-installed module version when it is newer
OR
Load both versions without shadowing
OR
Provide a setting to disable bundled modules
Actual Behavior
VS Code loads only the bundled module:
Impact
Script formatting is broken inside VS Code.
Users cannot rely on Invoke-Formatter for code cleanup.
The extension silently loads outdated modules.
This behavior contradicts PowerShell’s normal module resolution rules.
It creates confusion and breaks workflows that depend on PSScriptAnalyzer.
Recommendation
Provide a mechanism to:
Disable bundled modules
Prefer user-installed modules when newer
Or load both without shadowing
PowerShell Version
PS C:\Users\Michael\Documents\PowerShellWorkspace> $PSVersionTable.PSVersion; $HOST
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 6 6
Name : Visual Studio Code Host
Version : 2025.4.0
InstanceId : 5dbf22db-dded-40a4-a478-f3dc8e767566
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspaceVisual Studio Code Version
PS C:\Users\Michael\Documents\PowerShellWorkspace> code --version
1.136.1
a44adf7f53e00964ab890f9f8758a334f1fc15bc
x64Extension Version
PS C:\Users\Michael\Documents\PowerShellWorkspace> code --listExtensions code --list-extensions --show-versions | Select-String powershell
ms-vscode.powershell@2025.4.0Steps to Reproduce
Actual Behavior
VS Code loads only the bundled module:
Code
Directory: C:\Users<user>.vscode\extensions\ms-vscode.powershell-2025.4.0\modules
ModuleType Version Name
Script 1.24.0 PSScriptAnalyzer
The user-installed version is ignored:
Code
Directory: C:\Users<user>\OneDrive\Documents\PowerShell\Modules
ModuleType Version Name
Script 1.25.0 PSScriptAnalyzer
Calling Invoke-Formatter results in:
Code
Invoke-Formatter: The term 'Invoke-Formatter' is not recognized...
Reproduction Steps
Install PSScriptAnalyzer 1.25.0:
Code
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force
Open VS Code with the PowerShell extension enabled.
Run:
Code
Get-Module -ListAvailable PSScriptAnalyzer
Observe that VS Code loads only the bundled 1.24.0 version.
Attempt to run:
Code
Invoke-Formatter -ScriptDefinition "function Test { Write-Host 'hi' }"
Observe failure: Invoke-Formatter is not recognized.
Workaround
Rename the bundled module folder:
Code
C:\Users<user>.vscode\extensions\ms-vscode.powershell-2025.4.0\modules\PSScriptAnalyzer
→ PSScriptAnalyzer.bak
Restart VS Code’s PowerShell session.
After this, VS Code correctly loads the user-installed 1.25.0 version and Invoke-Formatter works.
Visuals
No response
Logs
No response
Activity