Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set-Location scope

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?

like image 866
Zombo Avatar asked Sep 11 '25 05:09

Zombo


1 Answers

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

finally
{
     Pop-Location
}
like image 144
David Brabant Avatar answered Sep 13 '25 21:09

David Brabant