Windows Powershell: Shortcut to Change Catalog

I just started using Windows Powershell, and one serious problem I encountered is when I start it, it launches me in this directory:

C:\Users\Username 

However, the directory I usually need to navigate to is something like:

 C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName 

And sometimes it goes much deeper. This way, you can see how annoying the navigation is a little every time I run the shell in this directory using ten separate cd commands. I was wondering if there is a way to create a shortcut or an alias for something like:

 cd C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName 

Or maybe I could set some kind of shortcut for the directory so that I can do something like:

 cd shortcut 

And it will be cd to the corresponding directory. Does anyone have any experience with this? Is this a stupid thing? I am very new to using any command line, so I'm just trying to get used to navigating files and folders.

+7
command-line command-line-interface shell powershell
source share
4 answers

Run this in powershell:

 start notepad $profile 

This will open your profile in notepad (notepad will prompt you to create it if it does not exist).

Any code that you write in this .ps1 file will run when powershell starts.

You can also set the system environment variable as if you set MYPSPATH to C:\Users\Username\Dropbox\Websites\2014\Projects , then you could do this:

 cd $env:MYPSPATH 

This can be done manually either every time or automatically in your $profile .

Also not clear from your question, but it looks like you are doing cd for each component of the path.

There is no need to do this. This command you like:

 cd C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName 

will work as is. If I misunderstood this moment, I apologize.

Something that may also be useful to you is pushd , which is an alias of Push-Location . This allows you to switch to a new directory and easily go back to where you started with popd or Pop-Location .

 PS C:\users\Xenostar> Push-Location .\Dropox\Websites\2014\Projects PS C:\users\Xenostar\Dropbox\Websites\2014\Projects> Pop-Location PS C:\users\Xenostar> 

And you can repeatedly press several levels and continue to return to the previous ones.

+7
source share

new-psdrive is your friend:

 New-PSDrive -Name docs -PSProvider FileSystem -Root "C:\Users\username\Documents" cd docs: 
+12
source share

There is another way:

 function PP { cd C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName } Set-Alias shortcut `PP` 
+8
source share

I believe this is the documentation you are looking to change the default location where powershell runs: Windows PowerShell Profile

+1
source share

All Articles