0

Context

When a PowerShell script installs components what modifies environment variables like PATH. This takes effect only when I close the console window, then reopen another.

If the following commands require the the changed environment, they will fail.

Question

I would like to run such a script without manual intervention, how can accomplish this? I found Powershell - Reboot and Continue Script, but that would be overkill. Is there any similar just to exit, then continue?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • It is not only about the PATH, that is just an example. – g.pickardou Feb 01 '19 at 16:30
  • The answer would be the same for any other environment variable. – Ansgar Wiechers Feb 01 '19 at 16:34
  • All methods described the referenced Q/A (for example 'refreshenv' has only effect on the Poweshell state. If the PATH changes, even after refreshenv, or more: start powershell, or start-process, the newly added command will not found. If I manually start a new PowerShell window, there it is... – g.pickardou Feb 01 '19 at 17:29
  • Enumerating the environment variables from the registry, and then reloading each of them is what I'd try first. If that doesn't help you need to investigate where the sessions differ. Just restarting a new PowerShell instance and terminating the old one could be done via `Start-Process powershell.exe; exit`, but there is no simple way to resume operation in the new instance, so reloading the environment in the current instance would be the preferred approach. – Ansgar Wiechers Feb 04 '19 at 00:30

0 Answers0