I have been tweaking some of the scripts in my PowerShell profile and it has got annoying to exit powershell then restart it so it will load any changes I have made to the scripts in my profile. Is it possible to restart the powershell session without exiting?
PowerShell NoExit switch prevents the PowerShell console window from closing after running the script. When you double click on the PowerShell script file, or run with the PowerShell option, the script will execute quickly and then disappear.
You can use the “Run as Administrator” option to open a command prompt in administrator privileges. Restart-Computer cmdlet in PowerShell reboots the local computer.
1: Reset PowerShell or Command Prompt to Default Settings If you know what setting you changed, you can revert by right-clicking on the top of a Powershell or Command Prompt window and click on Properites. Look for the setting you want to change. If you're not sure what was changed, click on Defaults.
To refresh the environment variables in PowerShell, retrieves the environment variables and assign them $Env:Path to reload the environment variable path in the PowerShell. After reloading the path in PowerShell, you don't need to restart the PowerShell ISE or terminal.
You can just do . $profile
to source the profile again.
This will start a new session, reloading your profile, in the same console window:
Invoke-Command { & "powershell.exe" } -NoNewScope # PowerShell 5 Invoke-Command { & "pwsh.exe" } -NoNewScope # PowerShell 7
Or a longer but more robust command, the following should work correctly across versions:
Get-Process -Id $PID | Select-Object -ExpandProperty Path | ForEach-Object { Invoke-Command { & "$_" } -NoNewScope }
You will, of course, lose all your variables etc. from the previous session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With