I use powershell to set a number of system environment variables, including the path. I then start some task with Start-Process. Unfortunately the new process has the same environment variables as those which powershell was started in. To reproduce the issue
1) Modify your path. I'm deleting %JAVA_HOME%/bin, open a command window and see that the java command does not work.
2) Start Powershell ISE
3) Add %JAVA_HOME%/bin to the system PATH. Open a new command window and see that the java command works.
4) In the previously opened Powershell window, submit the command start cmd to cause powershell to open a cmd.exe command window ("Command Prompt"). In the new command window verify that java does not work.
My expectation would be that a newly launched process would have its own fresh copy of the environment variables.
Can you tell me how to get powershell to launch a new task and have that task know the current environment?
I've tried
start cmd Start-Process -FilePath "cmd" Start-Process -FilePath "cmd" -UseNewEnvironment & cmd Thanks!
-UseNewEnvironmentswitch forStart-Processis designed to do what you want, but it is (still) broken as of PowerShell Core 7.0.0-rc.2 - see this GitHub issue.