0

just for understanding this.

I want to open my Powershell in a certain folder. As I didn´t find out how, I tried to put a batch file with just "cd ....." in it in the default folder where PowerShell opens. When I execute the batch, though, I end up where I started from. It seems that the batch gets excuted in a subshell which doesn´t affect the Parentshell.

How can I execute the stuff in the batchfile in parentshell ?

Thanks in advance!

2 Answers2

0

You cannot. Batch files are executed by cmd, not PowerShell, so there will always be a new process for them.

With a PowerShell script you can use dot-sourcing

. Script.ps1

To execute the script in your current scope, which is most similar to how batch files are executed by cmd by default.

Joey
  • 344,408
  • 85
  • 689
  • 683
0

If you want to open your Powershell in a certain folder, you can set that up in your Powershell profile. In Powershell, type $profile and that will give you the location of your profile file. Edit that file and use Set-Location:

Set-Location 'C:\Some\Place'

Powershell will execute whatever is in your profile script every time you open a new Powershell session.

Ben Richards
  • 3,437
  • 1
  • 14
  • 18