0

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
    pushd d:\temp; myProgram; popd – user364455 Apr 28 '17 at 3:15
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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