Skip to content

Set-Location breaks $PWD #9293

Closed
Closed

Description

Steps to reproduce

Steps documented below. $PWD.Path populates, but other members break (returning $null). This behavior does not happen by using Set-Location without piping.

Expected behavior

$ > Set-Location -Path C:\
$ > $PWD.Drive

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                  50.00        100.00 FileSystem    C:\

$ > Get-Item -Path C:\Windows | Set-Location
$ > $PWD.Drive

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                  50.00        100.00 FileSystem    C:\

$ >

Actual behavior

$ > Set-Location -Path C:\
$ > $PWD.Drive

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                  50.00        100.00 FileSystem    C:\

$ > Get-Item -Path C:\Windows | Set-Location
$ > $PWD.Drive
$ >

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 6.1.7601 S
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Apr 4, 2019
  2. vexx32 commented on Apr 4, 2019

    @vexx32
    Collaborator

    The issue isn't the pipe here, it's the type of item you're providing. You're piping in a DirectoryInfo object and not a string, which seems to cause Set-Location to actually use the PSPath property, seen here:

    PS Microsoft.PowerShell.Core\FileSystem::C:\windows> get-item c:\windows | Set-location
    PS Microsoft.PowerShell.Core\FileSystem::C:\windows> $pwd|fl *
    
    Drive        : 
    Provider     : Microsoft.PowerShell.Core\FileSystem
    ProviderPath : C:\windows
    Path         : Microsoft.PowerShell.Core\FileSystem::C:\windows
    

    Either the Set-Location command needs to be updated to normalize the path it's using properly, or whatever it's calling that causes $pwd to be updated needs to be fixed. Ideally, I'd want both fixed to double-check each other, tbh, just in case someone tries to be funny and update it themselves somehow in a weird way.

  3. morsley commented on Apr 4, 2019

    @morsley
    Author

    Rain Sallow (/u/ta11ow) (@vexx32) Thanks for the additional digging. I found this behavior also exists on Windows PowerShell. I noticed it because it kept breaking $Function:prompt

  4. vexx32 commented on Apr 4, 2019

    @vexx32
    Collaborator

    Aaaand I figured out a way to fix it.

    PS Z:\Scripts\PowerShell-Core> gi c:\windows|set-location
    PS C:\windows> $pwd
    
    Path
    ----
    C:\windows
    
    PS C:\windows> $pwd|fl *
    
    Drive        : C
    Provider     : Microsoft.PowerShell.Core\FileSystem
    ProviderPath : C:\windows
    Path         : C:\windows
    
  5. mklement0 commented on Sep 12, 2019

    @mklement0
    Contributor

    Update: This may be a separate problem - see #10522


    As of 7.0.0-preview.3, the problem is now more conspicuous:

    PS> Get-Item / | Set-Location
    PS Microsoft.PowerShell.Core\FileSystem::>
    

    Note the broken current location reported via the prompt function, based on the stringification of $executionContext.SessionState.Path.CurrentLocation (effectively, its .Path property).

    (As an aside: on Windows you'd get PS Microsoft.PowerShell.Core\FileSystem::C:\>, but on Unix the / gets eaten.)

  6. changed the title [-]Piping to `Set-Location` breaks `$PWD`[/-] [+]`Set-Location` breaks `$PWD`[/+] on Jan 30, 2020
  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions