{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7895","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7895/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7895/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7895/events","html_url":"https://github.com/PowerShell/PowerShell/issues/7895","id":365152388,"node_id":"MDU6SXNzdWUzNjUxNTIzODg=","number":7895,"title":"When using Workingdirectory parameter on pwsh, working directory gets set AFTER execution of $PROFILE script","user":{"login":"bergmeister","id":9250262,"node_id":"MDQ6VXNlcjkyNTAyNjI=","avatar_url":"https://avatars0.githubusercontent.com/u/9250262?v=4","gravatar_id":"","url":"https://api.github.com/users/bergmeister","html_url":"https://github.com/bergmeister","followers_url":"https://api.github.com/users/bergmeister/followers","following_url":"https://api.github.com/users/bergmeister/following{/other_user}","gists_url":"https://api.github.com/users/bergmeister/gists{/gist_id}","starred_url":"https://api.github.com/users/bergmeister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bergmeister/subscriptions","organizations_url":"https://api.github.com/users/bergmeister/orgs","repos_url":"https://api.github.com/users/bergmeister/repos","events_url":"https://api.github.com/users/bergmeister/events{/privacy}","received_events_url":"https://api.github.com/users/bergmeister/received_events","type":"User","site_admin":false},"labels":[{"id":401720735,"node_id":"MDU6TGFiZWw0MDE3MjA3MzU=","url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Area-Engine","name":"Area-Engine","color":"5319e7","default":false},{"id":423526741,"node_id":"MDU6TGFiZWw0MjM1MjY3NDE=","url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Issue-Discussion","name":"Issue-Discussion","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-29T17:44:06Z","updated_at":"2018-10-11T12:11:17Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"The default shortcuts for pwsh.exe on Windows are calling it using `-WorkingDirectory ~` by default, which is correct and by design.\r\nHowever, 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.\r\nUnfortunately, 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.\r\n\r\nSteps to reproduce\r\n------------------\r\nPut the following code into $profile\r\n```powershell\r\npwd\r\ncd C:\\\r\n```\r\n\r\nThen launch pwsh using the `-WorkingDirectory` parameter\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nThe 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\r\n\r\nActual behavior\r\n---------------\r\n\r\nThe 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.\r\n\r\nEnvironment data\r\n----------------\r\n\r\n<!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\n> $PSVersionTable\r\n\r\nName                           Value\r\n----                           -----\r\nPSVersion                      6.1.0\r\nPSEdition                      Core\r\nGitCommitId                    6.1.0\r\nOS                             Microsoft Windows 10.0.16299\r\nPlatform                       Win32NT\r\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion      2.3\r\nSerializationVersion           1.1.0.1\r\nWSManStackVersion              3.0\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/428931531","html_url":"https://github.com/PowerShell/PowerShell/issues/7895#issuecomment-428931531","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7895","id":428931531,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODkzMTUzMQ==","user":{"login":"DTW-DanWard","id":2632539,"node_id":"MDQ6VXNlcjI2MzI1Mzk=","avatar_url":"https://avatars1.githubusercontent.com/u/2632539?v=4","gravatar_id":"","url":"https://api.github.com/users/DTW-DanWard","html_url":"https://github.com/DTW-DanWard","followers_url":"https://api.github.com/users/DTW-DanWard/followers","following_url":"https://api.github.com/users/DTW-DanWard/following{/other_user}","gists_url":"https://api.github.com/users/DTW-DanWard/gists{/gist_id}","starred_url":"https://api.github.com/users/DTW-DanWard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DTW-DanWard/subscriptions","organizations_url":"https://api.github.com/users/DTW-DanWard/orgs","repos_url":"https://api.github.com/users/DTW-DanWard/repos","events_url":"https://api.github.com/users/DTW-DanWard/events{/privacy}","received_events_url":"https://api.github.com/users/DTW-DanWard/received_events","type":"User","site_admin":false},"created_at":"2018-10-11T12:11:17Z","updated_at":"2018-10-11T12:11:17Z","author_association":"NONE","body":"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."}}
{"actor":{"display_login":"DTW-DanWard"}}