You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When using Workingdirectory parameter on pwsh, working directory gets set AFTER execution of $PROFILE script #7895
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Enginecore PowerShell engine, interpreter, and runtime
The default shortcuts for pwsh.exe on Windows are calling it using -WorkingDirectory ~ by default, which is correct and by design.
However, if I wanted to temporarily change/set the final working directory, then the most intuitive way for most users (not familiar with this new feature) would be to add code like cd C:\foo into the $PROFILE script.
Unfortunately, only AFTER executing the script in $PROFILE, the working directory gets set to the one specified by the WorkingDirectory parameter. If it got set BEFORE executing the $PROFILE script then this problem would not exist and the working directory when $PROFILE executes would be a more reasonable one as well.
Steps to reproduce
Put the following code into $profile
pwd
cd C:\
Then launch pwsh using the -WorkingDirectory parameter
Expected behavior
The printed working directory when executing the script in $PROFILE should be the one specified by -WorkingDirectory of pwsh, therefore the $PROFILE should be able to override and change that working directory
Actual behavior
The working directory when the $PROFILE script executes is C:\Windows\System32 instead of the path specified by the -WorkingDirectory parameter on pwsh, the final working directory is not C:\ as it is being set inside the script.
Environment data
>$PSVersionTable
Name Value
---------
PSVersion 6.1.0
PSEdition Core
GitCommitId 6.1.0
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Reacted by Michael Klement, Dan Ward and ant@devantic
This has been driving me nuts the past few days. Maybe a quick solution is to not add the WorkingDirectory parameter to the shortcuts...? Developers/desktop users are always going to set the default location via profile, not by changing the shortcut value. WorkingDirectory seems only useful for automating a script or running one remotely. But, to be honest, even then I wouldn't rely upon it; if my script had to be in a default location at start-up I would ensure that at the beginning of the script itself and not trust that the shell had been opened to the correct default location.
We should rather fix this properly in the implementation of the new Workingdirectory parameter that was introduced in PR #6612 to help start PowerShell by default in the user folder instead of its installation folder and for an issue with the explorer context menu. cc Steve Lee (@SteveL-MSFT)
The proposed design would be to have the WorkingDirectory ready before execution of the $PROFILE script instead afterwards.
If the working directory is going to be set the user should be given the option of overriding the default when PowerShell is installed. we get the option to override the install folder why not the workingdirectory?
RichardSiddaway We could certainly add an option to specify a different working directory for the start menu shortcut (or nothing at all, pwsh would then start in the installation folder) but this would not address the problem highlighted by this issue where the working directory gets set too late.
The reason why the user can choose the installation folder is just because it is part of the basic WiX template that provides this functionality out of the box for free.
It may not solve the conflict between the profile and the -workingdirectory parameter but it would effectively remove the conflict or the need to set a directory in your profile. It would also be a potential (partial) solution to issue #8069
I think for the majority of users, having the -WorkingDirectory ~ in the shortcut is the preferred experience to have it default to their home directory than $PSHOME. The fix for this immediate problem is simple, just move the processing of -WorkingDirectory earlier although it could have a breaking change impact if $PROFILE expects to start in $PSHOME.
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Enginecore PowerShell engine, interpreter, and runtime
Activity
DTW-DanWard commentedon Oct 11, 2018
This has been driving me nuts the past few days. Maybe a quick solution is to not add the WorkingDirectory parameter to the shortcuts...? Developers/desktop users are always going to set the default location via profile, not by changing the shortcut value. WorkingDirectory seems only useful for automating a script or running one remotely. But, to be honest, even then I wouldn't rely upon it; if my script had to be in a default location at start-up I would ensure that at the beginning of the script itself and not trust that the shell had been opened to the correct default location.
bergmeister commentedon Oct 11, 2018
We should rather fix this properly in the implementation of the new
Workingdirectoryparameter that was introduced in PR #6612 to help start PowerShell by default in the user folder instead of its installation folder and for an issue with the explorer context menu. cc Steve Lee (@SteveL-MSFT)The proposed design would be to have the WorkingDirectory ready before execution of the $PROFILE script instead afterwards.
RichardSiddaway commentedon Oct 18, 2018
If the working directory is going to be set the user should be given the option of overriding the default when PowerShell is installed. we get the option to override the install folder why not the workingdirectory?
bergmeister commentedon Oct 18, 2018
RichardSiddaway We could certainly add an option to specify a different working directory for the start menu shortcut (or nothing at all, pwsh would then start in the installation folder) but this would not address the problem highlighted by this issue where the working directory gets set too late.
The reason why the user can choose the installation folder is just because it is part of the basic WiX template that provides this functionality out of the box for free.
RichardSiddaway commentedon Oct 18, 2018
It may not solve the conflict between the profile and the -workingdirectory parameter but it would effectively remove the conflict or the need to set a directory in your profile. It would also be a potential (partial) solution to issue #8069
SteveL-MSFT commentedon Oct 19, 2018
I think for the majority of users, having the
-WorkingDirectory ~in the shortcut is the preferred experience to have it default to their home directory than $PSHOME. The fix for this immediate problem is simple, just move the processing of-WorkingDirectoryearlier although it could have a breaking change impact if $PROFILE expects to start in $PSHOME.