-
Notifications
You must be signed in to change notification settings - Fork 511
pwsh.exe
$env:PSModulePath
Retained In 5.1 Console When code.cmd
Called From pwsh.exe
#3886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Import-PowerShellDataFile
- Not Recognized As The Name Of A Cmdlet In Ps Integrated Console 5.1Import-PowerShellDataFile
- Not Recognized In Ps Integrated Console 5.1
Import-PowerShellDataFile
- Not Recognized In Ps Integrated Console 5.1Import-PowerShellDataFile
- Not Recognized In Integrated Console 5.1
Import-PowerShellDataFile
- Not Recognized In Integrated Console 5.1Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1
I was also able to install and import the linked Do you have WMF 5.1 installed? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This Windows is Version 21H2, OS Build 22000.556. Do you have any updates available? |
Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1 On Non-Elevated code.cmd
This comment was marked as outdated.
This comment was marked as outdated.
Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1 On Non-Elevated code.cmd
Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1 From Non-Elevated code.cmd
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Import-PowerShellDataFile
Not Recognized In Integrated Console 5.1 From Non-Elevated code.cmd
Microsoft.PowerShell.Utility
7.0.0
Loaded When code.cmd
Called from pwsh.exe
Microsoft.PowerShell.Utility
7.0.0
Loaded When code.cmd
Called from pwsh.exe
Microsoft.PowerShell.Utility
7.0.0
Loaded In 5.1 Console When code.cmd
Called from pwsh.exe
Strange...to answer your question earlier, no, I don't load Code in an admin prompt. Does seem like a path issue if you're starting with pwsh.exe, then opening Code (with the PSModulePath set from pwsh.exe) and then starting powershell.exe. I would recommend either opening Code directly (not from pwsh.exe) or from the same version of PowerShell you then want to use in Code (so powershell.exe to Code back to powershell.exe). |
That is unfortunate. I prefer If that is the solution and there is nothing more to debug, then ok. I would think there shouldn't be any sharing of paths when |
Can you check |
That's an operating system thing... so here's how environment variables work: You start
From that process (where the environment variable is set) you start
and in a spawned
Since we just take the environment variable Now that said, in my experimenting it seems that And then the actual trim logic here: So I'm going to leave this open as a bug, because we could duplicate PowerShell's existing workaround and improve this behavior for you. |
I'll spend some time reviewing your robust explanation soon, Andy. I really appreciate the large response! EDIT: My PS> $env:PSModulePath -split ';'
C:\Users\user\OneDrive\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
C:\Program Files\Veeam\Backup and Replication\Explorers\Exchange\
C:\Program Files\Veeam\Backup and Replication\Explorers\SharePoint\
C:\Program Files\Veeam\Backup and Replication\Explorers\SQL\
C:\Program Files\Veeam\Backup and Replication\Explorers\ActiveDirectory\
C:\Program Files\Veeam\Backup and Replication\Explorers\Oracle\
c:\Users\user\.vscode\extensions\ms-vscode.powershell-preview-2022.3.0\modules EDIT 2: Sorry I got distracted and didn't see your response below. |
So that's exactly why I left if open. If you open |
Microsoft.PowerShell.Utility
7.0.0
Loaded In 5.1 Console When code.cmd
Called from pwsh.exe
code.cmd
Called From pwsh.exe
$env:PSModulePath
Paths Retained In 5.1 Console
code.cmd
Called From pwsh.exe
$env:PSModulePath
Paths Retained In 5.1 Consolecode.cmd
Called From pwsh.exe
$env:PSModulePath
's Paths Retained In 5.1 Console
code.cmd
Called From pwsh.exe
$env:PSModulePath
's Paths Retained In 5.1 Consolecode.cmd
Called From pwsh.exe
, Non-powershell.exe
$env:PSModulePath
Paths Retained In 5.1 Console
code.cmd
Called From pwsh.exe
, Non-powershell.exe
$env:PSModulePath
Paths Retained In 5.1 Consolecode.cmd
Called From pwsh.exe
, Non-powershell.exe
$env:PSModulePath
Retained In 5.1 Console
code.cmd
Called From pwsh.exe
, Non-powershell.exe
$env:PSModulePath
Retained In 5.1 Consolepowershell.exe
$env:PSModulePath
Retained In 5.1 Console When code.cmd
Called From pwsh.exe
powershell.exe
$env:PSModulePath
Retained In 5.1 Console When code.cmd
Called From pwsh.exe
pwsh.exe
$env:PSModulePath
Retained In 5.1 Console When code.cmd
Called From pwsh.exe
Prerequisites
Summary
Issue found when
Import-PowerShellDataFile
was not recognized becauseMicrosoft.PowerShell.Utility
7.0.0
is loaded in 5.1 Integrated Console. The libraries version is incorrect within the Visual Studio Code Host ( e.g.$Host
) onpowershell.exe
5.1
when user launchescode.cmd
frompwsh.exe
. The$env:PSModulePath
is retained from the parentpwsh.exe
session and causes issues in thepowershell.exe
session withincode.exe
.powershell.exe
on it's own purges thepwsh.exe
paths from the module path ( e.g.C:\Program Files\PowerShell\Modules
andC:\program files\powershell\7\Modules
). See this comment on the code links to the PowerShell code base.Modules like
Terminal-Icons
error out. I still need to use this version due to SOAP endpoints like SQL Server Reporting Services ( e.g.ReportingServicesTools
module ).PowerShell Version
Visual Studio Code Version
Extension Version
Steps to Reproduce
Set Integrated Console in VS Code to Windows Powershell (x64). Close all instances of VS Code.

Execute below in VS Code Integrated Terminal
Visuals
N/A
Logs
Terminal Log Output
Attached are the corresponding logs files.
StartEditorServices.log
vscode-powershell.log
EditorServices.log
The text was updated successfully, but these errors were encountered: