4

Given this file

Set-Location C:\

If I run it

.\foo.ps1

It will change the directory in the script. However once the script is finished the parent console directory has also been changed. Can Set-Location be called in such a way as to affect only the running script?

Zombo
  • 1
  • 62
  • 391
  • 407

1 Answers1

8
try
{
     Push-Location
     Set-Location c:\
     # your code here ...
}

finally
{
     Pop-Location
}
David Brabant
  • 41,623
  • 16
  • 83
  • 111