Skip to content

PowerShell Extension Overrides Set-Location Command in Profile.ps1 #4788

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

Closed
4 of 6 tasks
joeywizard opened this issue Oct 19, 2023 · 0 comments · Fixed by PowerShell/PowerShellEditorServices#2091
Closed
4 of 6 tasks
Assignees

Comments

@joeywizard
Copy link

joeywizard commented Oct 19, 2023

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

After PowerShell Extension v2023.8.0 was installed, Terminal sets the working directory of command prompt to the directory of the folder specified in a previous session. This is new, unexpected behavior since the "PowerShell: Enable Profile Loading" option is selected and a "CurrentUserAllHosts" Profile.ps1 exists that contains a Set-Location command that sets the working directory to a different location. Note that the "PowerShell: Cwd" option is not populated (i.e., the value is empty).

The "CurrentUserAllHosts" Profile.ps1 has the following relevant commands:
New-PSDrive -Name Home -PSProvider FileSystem -Root "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowerShell" | Out-Null
Set-Location -Path Home:\

Prior to PowerShell extension v2023.8.0, Terminal would default to the correct directory, which is the path specified in the Set-Location command. So, in my case, the command prompt would display as follows:

PS Home:>

PowerShell Version

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.2428
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2428
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

PS> code --version
1.83.1
f1b07bd25dfad64b0167beb15359ae573aecd2cc
x64
PS D:\Users\Joe\OneDrive\PowerShell>

Extension Version

PS> code --list-extensions --show-versions | Select-String powershell

[email protected]

Steps to Reproduce

  1. Open Visual Studio Code.
  2. Open a folder containing PowerShell scripts.
  3. View Terminal if Terminal is not visible.
  4. Note the command prompt and the current working directory is set to the folder that was opened.

Visuals

No response

Logs

File is attached
EditorServicesDiagnosticLevelOutput.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants