Skip to content

PowerShell doesn't set current working directory correctly #19446

@SetTrend

Description

@SetTrend

Prerequisites

Steps to reproduce

Writing a binary module I noticed that the current working directory isn't set correctly on Windows.

[System.Environment]::CurrentDirectory always returns C:\Windows\system32, no matter what.

Expected behavior

PS> Set-Location 'C:\Temp'
PS> [System.Environment]::CurrentDirectory
C:\Temp

Actual behavior

PS> Set-Location 'C:\Temp'
PS> [System.Environment]::CurrentDirectory
C:\Windows\system32

Environment data

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

Visuals

PowerShell CWD error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions