How to prevent command/script from changing global environment
Posted
by guillermooo
on Stack Overflow
See other posts from Stack Overflow
or by guillermooo
Published on 2010-05-30T22:24:11Z
Indexed on
2010/05/30
22:32 UTC
Read the original article
Hit count: 201
powershell
|subshell
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?
© Stack Overflow or respective owner