How to change the default directory of the PowerShell console? [Quick Guide]

6:29 pm April 6, 20178303

I. introduction

when opening a console PowerShell on Windows, by default it is positioned at the root of the directory of the user who launches the console. However, there is little chance that you store your scripts to this place that is not necessarily suited… A little trick is to change the default directory to position themselves directly in another directory.

For example, it may “C:scripts” or another directory corresponding to your GitHub repository locally, for example it allows quick access to your creations.

Let’s see how to do this.

II. adding of Set-Location in your profile

with PowerShell, you have the ability to manage a profile to personalize your environment, it may be to directly include the loading of your own functions, change the colors of the console, etc… But also change the default location.

Maybe you know if your profile file exists or not, to check it out it is very simple:

 Test-Path $PROFILE 

which will return a Boolean:

if the profile file does not exist, we’re going to recreate it:

 New-Item - Type File - Path $PROFILE 

it should be noted that the $PROFILE variable is automatic and contains the path to your personal profile file : C:UsersFlorianDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1

Puis we’ll edit it:

 notepad.exe $PROFILE 

complete example:

we are left with our open profile file, it remains only to feed it! To meet our need to change the default directory, we’ll use the “Set-Location” cmdlet that can move in the data tree (equivalent to the command cd ).

Simply specify Set-Location followed the path that you want to use, like this:

just close your console PowerShell or open another, to see that the console will launch directly into the new directory:

a tip from the simple PowerShell console , but handy!