1

My powershell script contain a 'set-location' (cd) command. After running the script, my current directory is changed, but I don't want it that way.

test.ps1:

cd d:\temp (new line)
myProgram (new line)
(eof)

Those 'new line', 'eof' are markings only.

PowerShell console:

PS D:\projects\abc> .\test.ps1
This line is the output of myProgram
PS D:\temp> _

I need my PowerShell console stay in d:\projects\abc instead of being at d:\temp after running the script. Any quick solution?

I can not just run d:\temp\myProgram because myProgram is only working in that d:\temp directory. And also, I can't put "cd d:\projects\abc" after executing myProgram in test.ps1 as myProgram is a web server which I have to terminate when I want using Ctrl+C.

1
  • 1
    pushd d:\temp; myProgram; popd
    – user364455
    Apr 28, 2017 at 3:15

1 Answer 1

2

Solution by PetSerAl in the comment under question:

pushd d:\temp
myProgram
popd

I found another solution too

PS D:\projects\abc> powershell .\test.ps1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .