Powershell: Calling Set-Location without any parameters changes location to %UserProfile% directory

Created on 2 May 2018  路  6Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Call Set-Location or cd

PS C:\Users\gakama\Desktop> set-location D:\
PS D:\> cd
PS C:\Users\gakama> set-location D:\
PS D:\> Set-Location
PS C:\Users\gakama>

Expected behavior

Without any parameters, it shouldn't change the current location.

Here's the output from Powershell 5.1

PS C:\Users\gakama\Desktop> Set-Location d:
PS D:\> cd
PS D:\>

Actual behavior

The location changes to "%USERPROFILE%" (C:\Users\<username>)

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
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

Issue-Discussion Resolution-By Design

Most helpful comment

All 6 comments

This was an explicit design decision (and yes, a breaking change from Windows PowerShell) mimicking Bash

Coming from Windows it caught me by surprise.

Is this change documented?

@SteveL-MSFT It's really amazing behavior on Windows because Windows users expect in contrast to Unix that default working directory is Documents not profile root folder.

/cc @mklement0 What do you think?

@iSazonov:

The behavior is consistent: the equivalent locations - $HOME - are targeted on all platforms.

It is a fact of Windows life that creating files and folders _directly_ in $HOME is _ill-advised_ - albeit _possible_. Yes, using Documents for user-created content is the right choice, but it is only a _convention_.

This asymmetry in how the $HOME folder is used between Unix-like platforms and Windows is unfortunate, but in this case I think it's more important to be consistent and stick with the well-defined, directly equivalent $HOME on all platforms.

That said, it would generally be handy for Set-Location to support the special / well-known folders supported by [Environment]:: via the [Environment+SpecialFolder] enumeration, so that you could do something like:

Set-Location -SpecialFolder MyDocuments 

See #6966

Was this page helpful?
0 / 5 - 0 ratings