Refreshing/Restarting PowerShell session w/out exiting
@manojlds' answer is right, but it could end up throwing errors. For example, if you've defined a new PSDrive in your profile, then re-dotsourcing it may cause errors.
An alternative approach is to first start powershell, then immediately start another version inside by just typing PowerShell. I make the changes to my profile in the nested console, exit, then rerun PowerShell to test the updated profile.
Another thing - make profile changes slowly and carefully. In my view, while profiles do need to evolve, that evolution typically should be slow. YMMV!!
This will start a new session, reloading your profile, in the same console window:
Invoke-Command { & "powershell.exe" } -NoNewScope # PowerShell 5Invoke-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.