Skip to content

When using Workingdirectory parameter on pwsh, working directory gets set AFTER execution of $PROFILE script #7895

@bergmeister

Description

@bergmeister

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

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions