How to prevent command/script from changing global environment
- by guillermooo
I need to run scriptblocks/scripts from the current top-level shell and I want them to leave the global environment unmodified.
So far, I've only been able to think of the following possibilities:
powershell -file <script>
powershell -noprofile -command <scriptblock>
The problem is, that they are very slow.
For instance, I would like to be able to do:
mkdir newdir
cd newdir
$env:NEW_VAR = 100
ni -item f 'newfile.txt'
...so that my shell's working dir wouldn't change and $env:NEW_VAR wouldn't be set in the global environment.
Are there any more alternatives to accomplish this?