vscode-powershell
vscode-powershell copied to clipboard
Extension Fails to start using PowerShell 7 if Windows PowerShell module path is above the PS7 module path in $PSMODULEPATH
Prerequisites
- [X] 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.
- [X] 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
Hi,
This is the second time when I face this situation. Scenario: Fresh install of Visual Studio Code (VSC), then install PowerShell extension from Microsoft. Upon requesting to trust publisher, I press A (always trust) in the terminal window and then nothing happens. I leave it for 1-2h without nothing to happen and then force to stop it. Restarting VSC and Windows PowerShell (x64) is never loading, the bottom-right icon is spinning forever. Switching to Windows PowerShell (x86) is working. The first time when this happened was 2-3 years ago and I remember I've spent also lot of time trying to figure out how to fix this. I discovered the fix by mistake: Found a post about OneDrive somehow corrupting some PowerShell (psm/psd) files from Documents folder or someting. Running chkdsk from command propmt fixed the issue. But now this doesn't seems to have any effect. Any ideas what can I do?
Thanks, Marius.
PowerShell Version
Name Value
---- -----
PSVersion 5.1.22621.4249
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.4249
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Name : Windows PowerShell ISE Host
Version : 5.1.22621.4249
InstanceId : 64347789-db94-40f5-9118-5d2a0c2cc76b
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Visual Studio Code Version
1.94.0
Extension Version
v2024.2.2
Steps to Reproduce
See Summary section
Visuals
No response
Logs
No response
This is how terminal looks like
Been having the same issue for the past week or so. Seems to only happen when switching the session to PS 5.1. My workaround is to switch the shell by running powershell in my pwsh session, instead of using the PowerShell: Show Session Menu -> Switch to: command.
Thanks for the submission! The most common reason we've been seeing this lately is an antivirus program blocking or halting the execution of the PowerShell extension. Do you have any antivirus programs installed?
Otherwise there's not much we can do without a reproducible method, I just tried it in a fresh Windows Server and Windows 11 VM and both worked fine, can you install PowerShell 7? PowerShell 5.1 is as-is support, PowerShell 7 will work better even if you are only authoring 5.1 scripts.
So I've actually seen multiple reports on this so there might be something, but on my Win11 machine and in a clean environment, WinPS 32, WinPS64, and PS7.4 all load just fine with 1.94 vscode.
@andyleejordan FYI in case you have an idea.
Report from jcotton42 on discord
I wonder, is it related to the shell integration path moving? They released that changer sooner than I expected so we're temporarily broken. Working on getting a release out ASAP.
Been having the same issue for the past week or so. Seems to only happen when switching the session to PS 5.1. My workaround is to switch the shell by running
powershellin mypwshsession, instead of using thePowerShell: Show Session Menu -> Switch to:command.
I will try it, thanks.
Thanks for the submission! The most common reason we've been seeing this lately is an antivirus program blocking or halting the execution of the PowerShell extension. Do you have any antivirus programs installed?
Otherwise there's not much we can do without a reproducible method, I just tried it in a fresh Windows Server and Windows 11 VM and both worked fine, can you install PowerShell 7? PowerShell 5.1 is as-is support, PowerShell 7 will work better even if you are only authoring 5.1 scripts.
I have the built in MS Defender, that's all. I tried on other machines and it's working, it's something particular on my machine.
Hi,
Anyone knows how can I trigger again that popup/dialog with adding a trust publisher when installing an extension? I mean the very first time when you install a extension from a publisher and you are asked if you trust that publisher. I'm trying to untrust and trust again that publisher maybe it works. For that I uninstalled Visual Studio Code and then removed .vscode folder from user's folder and also Code folder from C:\Users<USER_NAME>\AppData\Roaming. No luck, only initial setup was triggered (choosing theme, etc).
Thanks, Marius.
This is the trust publisher question which never ends when I press A: "Do you want to run software from this untrusted publisher? File C:\Users\MyUserName.vscode\extensions\ms-vscode.powershell-2022.11.0\modules\PowerShellEditorServices\Commands\PowerShellEditorServices.Commands.types. ps1xml is published by CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your system. Only run scripts from trusted publishers. [V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is "D"):"
Hi, I solved the same issue by run this powershell command: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
this will allow to run powershell scripts with the curret user (both on Powershell ISE and Visual Studio Code)
Hi, I solved the same issue by run this powershell command:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedthis will allow to run powershell scripts with the curret user (both on Powershell ISE and Visual Studio Code)
@alberto-bottacin thank you so much Confirmed! This, setting the executionpolicy, fixed it for me.
Just had the problem too. Then I noticed that it happens only when I open VS-Code by running code in a PowerShell (Core)/7.5 console. For example, running code C:\projecty\myproject) in 7.5 and if the extension then wants to start with Windows PowerShell/5.1 it hangs. When I start VS-Code normally and then open the directory then it works fine.
Maybe it relates somehow to this https://github.com/PowerShell/vscode-powershell/issues/5001 For me the PSModulePath in 7.5 includes the Windows PowerShell paths too. Not sure why but I do not remember to change anything manually here. The PowerShell extension seems to not like that anyhow.
Just had the problem too. Then I noticed that it happens only when I open VS-Code by running
codein a PowerShell (Core)/7.5 console. For example, runningcode C:\projecty\myproject) in 7.5 and if the extension then wants to start with Windows PowerShell/5.1 it hangs. When I start VS-Code normally and then open the directory then it works fine.
That is this extant bug: https://github.com/PowerShell/vscode-powershell/issues/3886
In your scenario, we're at the mercy of how child processes inherit environment variables. We have identified a "fix" which is to sanitization of the PSModulePath variable (which while a little bonkers to suggets...is what PowerShell itself can be found doing). Can anyone else confirm that this GitHub issue is specific to this scenario?
Just had the problem too. Then I noticed that it happens only when I open VS-Code by running
codein a PowerShell (Core)/7.5 console. For example, runningcode C:\projecty\myproject) in 7.5 and if the extension then wants to start with Windows PowerShell/5.1 it hangs. When I start VS-Code normally and then open the directory then it works fine.Maybe it relates somehow to this #5001 For me the PSModulePath in 7.5 includes the Windows PowerShell paths too. Not sure why but I do not remember to change anything manually here. The PowerShell extension seems to not like that anyhow.
Interesting, just tried this and seems to work for me as well, huh. I seem to have two terminals/shells pwsh and PowerShell Extension (don't really understand what is going on, but hopefully this description makes sense), but both load and get my intellisense back. Will see if debugging works next.
@andyleejordan just read your comment, so tagging you in this reply as I had similar experience.
I am having similar issue. As per comment above @J0F3 's suggestiong of launching VSCode then loading project, as opposed to code . within project folder in WindowsTerminal powershell 7.5 console.
I then have two terminals (hope I'm describing this well as I don't really understand what is going on in vscode) in VSCode: -
- pwsh PSVersion 7.5.0
- PowerShell Extension PSVersion 5.1.26100.2161
Hope that makes (some) sense/is helpful.
Update to my earlier post: I didn't actually need to have two different versions of Powershell running i.e. terminal and the powershell extension. After un-checking profile loading for the extension and setting the default version to Powershell (x64) i.e. core powershell it seems I can load via cli code . and the extension now loads.
Thanks for the submission! The most common reason we've been seeing this lately is an antivirus program blocking or halting the execution of the PowerShell extension. Do you have any antivirus programs installed?
Otherwise there's not much we can do without a reproducible method, I just tried it in a fresh Windows Server and Windows 11 VM and both worked fine, can you install PowerShell 7? PowerShell 5.1 is as-is support, PowerShell 7 will work better even if you are only authoring 5.1 scripts.
^^^^^This makes sense. I have a Win11 Defender personal system and all is well with the PowerShell extension.
I have a CrowdStrike corporate system that ran
ms-vscode.powershell Version 2025.0.0
until it didn't. All efforts to get the extension to stop looping are to no avail.
Overkill Procedure
- Remove the extension and close Code
- Install the latest PowerShell
- Clear Code module cache
- Update Code
- Update extensions
- Update Help
- Open Code, install the PowerShell extension, and close Code
- Open Code, select a .ps1, and cross fingers
PowerShell extension is looping. Switch to pwsh and move on
I am experiencing the same symptoms, although I can get VS Code (Insiders) / PowerShell extension to work If I launch "Code-Insiders.cmd" and NOT "code - insiders.exe".
So for anyone having this issue, try launching the batch file (mine is located at "C:\Program Files\Microsoft VS Code Insiders\bin\code-insiders.cmd" instead.
Looking at the batch file, I suspect something in cli.js with the environment variables is the causing the PS extension to work.
I am experiencing the same symptoms, although I can get VS Code (Insiders) / PowerShell extension to work If I launch "Code-Insiders.cmd" and NOT "code - insiders.exe".
So for anyone having this issue, try launching the batch file (mine is located at "C:\Program Files\Microsoft VS Code Insiders\bin\code-insiders.cmd" instead.
Looking at the batch file, I suspect something in cli.js with the environment variables is the causing the PS extension to work.
Using insider may solve part of the problem. The following code snippet works in my corporate network from Start->Terminal.
PS> winget update --id Microsoft.VisualStudioCode; Code --update-extensions; Update-Help -UICulture en-US -ErrorAction SilentlyContinue
but any attempt to run the Install-Module cmdlet hangs in the Code terminal and Start->Terminal.
I don't have any PowerShell or VSCode issues on my personal system running Defender anti-virus policies. I'm chalking up this reported issue to the corporate anti-virus policy.
I was having the same issue, and I figured it out. It has to do with your system environment variables.
Previously my symptoms were as follows:
Right click pinned VS Code from Task Bar > New Window > Open Folder
The PowerShell Extension never loads, spins and IntelliSense\Linting issues doesn't work.
Output tab:
2025-05-30 15:29:58.353 [info] Visual Studio Code: v1.100.2 64-bit on Windows 64-bit
2025-05-30 15:29:58.353 [info] PowerShell Extension: v2025.0.0
**2025-05-30 15:30:00.903 [info] Starting 'Windows PowerShell (x64)' at: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe**
2025-05-30 15:30:01.168 [info] PowerShell process started with PID: 50772
Think to myself C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe is kind of weird.
When hovering over the Extension terminal:
There it is again, should it be loading from C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe? That didn't seem right to me, so I checked my variables.
Right click Start Button > System > Advanced System Settings > Environment Variables
Under System Variables (the bottom part) I first checked Path and noticed I had a ton of duplicates for some reason, so I removed them.
I then compared to another computer with a working VS Code and moved these to the top to match the working computer:
A major difference between my working computer and the one having issues was the variables in PSModulePath
On the non-working computer these were hardcoded, on my working computer they were set as:
I applied the above images settings on the non-working computer, saved and rebooted.
Issue resolved! Not sure if the fix was the Path ordering or PSModulePath - but check both of those and hopefully it solves anyone else's problem too.
Again we strongly recommend you use PowerShell 7 in the extension terminal, your experience will be miles better. You can still author 5.1 scripts and run 5.1 side-by-side in another terminal to test.
Same problem here. In the Command line there seems to be a missing backslash after the user folder:
Maybe that is causing the hang?
Same here. Nothing helping. Notes
- PS 5.1 - if starting vscode from Taskbar, StartMenu or by open with Code - not working, if executing from AppData\Local\Programs\Microsoft VS Code\bin\code.cmd it is working....
- PS7 - Working for all cases.
Same here. Nothing helping. Notes
- PS 5.1 - if starting vscode from Taskbar, StartMenu or by open with Code - not working, if executing from AppData\Local\Programs\Microsoft VS Code\bin\code.cmd it is working....
- PS7 - Working for all cases.
had the same issue on two of my computer with limited internet access. Extension targeting PS5.1 was hanging since moving to 1.101.1. with Extension version 2025.3.0 and 2025.3.1
using the code.cmd solved the problem.
modified code.cmd from "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %* to Start "VSCode" "%~dp0..\Code.exe" "%~dp0..\resources\app\out\cli.js" %* so the command windows close immediatly after starting code.
I need extension on 5.1 to make the temporary terminal start in 5.1.
I concur. On my internet-connected machine, launching VS Code via Start Menu or taskbar works fine with PS 5.1 sessions. But on machines with restricted or no internet access, the only reliable method is launching via code.cmd. Like others, I also observed that PS7 works flawlessly in all launch scenarios.
Using code.cmd consistently initializes the PS 5.1 session correctly. Still relying on PS 5.1 for specific scenarios, so this workaround is crucial for now. Thanks for sharing!
I concur. On my internet-connected machine, launching VS Code via Start Menu or taskbar works fine with PS 5.1 sessions. But on machines with restricted or no internet access, the only reliable method is launching via code.cmd. Like others, I also observed that PS7 works flawlessly in all launch scenarios.
Using code.cmd consistently initializes the PS 5.1 session correctly. Still relying on PS 5.1 for specific scenarios, so this workaround is crucial for now. Thanks for sharing!
I've made some additional tests this afternoon and cannot reproduce the problem on a fully isolated and sec tools free workstation. I suspect Crowdstrike as by procmon analysis. I will do more tests tomorrow
@SwissPowershell I use Windows Defender on disconnected network
To reiterate my 2025-05-06 comment I have a Win11 Defender personal system and all is well with the PowerShell extension.
Corporate system hangs on PowerShell Extension v2025.0.0 CrowdStrike PowerShell v7.5.1 Code v1.00.2 from the CLI or Start menu
just tested Insider v1.102.0-insider with PowerShell Extension v2025.0.0 also hangs