Learn about Windows PowerShell
Summary: Reload your Windows PowerShell profile without closing and reopening Windows PowerShell.
How can I reload my Windows PowerShell profile to test some changes I made—without closing and reopening Windows PowerShell?
Use the invocation operator with the automatic $profile variable:
Note Depending on how you have written your profile, you may generate a large number of errors, for example, Drive already exists or Alias already exists.
I had some problems with "& $profile" (fonction not updated), I use ". $profile" instead and it works fine.
Etienne should be right, . instead &.
@Etienne Divina @Larry I just retested this, and on my Windows 8 laptop running PowerShell 3.0 both techniques work. Keep in mind, that if you do not have a profile (use notepad $profile to check) then neither technique works.
Just tested this in powershell 4.0 on windows server 2008 R2.
It does not work.
Dot sourcing did work, however, I am not sure dot sourcing is the exact equivalent of reloading the profile.
My understanding is that dot sourcing can 'pollute' the session with conflicting variable names etc...
Would be nice if there was a technique to just reload the profile.
Dot sourcing is the better way. dot sourcing will guarantee that it is run globally. Normally variables defined in a script are not global. Dot sourcing makes them global. Functions that are defined are persisted globally.