I have a .bat script that just cds into a directory


cd \Users\Me\Documents\NetBeansProjects\

It is in my home folder. (C:\Users\Me)

In cmd when I run it

C:\Users\Me>cd \Users\Me\Documents\NetBeansProjects\

It works as expected, I'm in the NetBeans directory. In powershell, I get this

PS C:\Users\Me> .\cddocs

C:\Users\Me>cd \Users\Me\Documents\NetBeansProjects\
PS C:\Users\Me>

So it appears to run the cd command, but I am still in my home directory! I must be missing something really simple here. How can I get this tiny script to actually cd the directory in powershell?


Your powershell environment is launching your script in a cmd batch context.

In this context, the script is changing his current directory (with your 'cd' command). After that, the script exits.

When the script exits of the cmd batch context, the context is destroyed and you come back in the initial powershell context which did not change it's current directory.

  • so that explains the why, however, how can I create a script to change the directory in the "PS" context? – chiliNUT Apr 22 '16 at 16:59
  • "how can I create a script to change the directory in the "PS" context" Write a PowerShell script (.ps1) instead of trying to use a batch file? – Ƭᴇcʜιᴇ007 Apr 22 '16 at 17:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.