AymenDaoudi AymenDaoudi - 11 months ago 143
PowerShell Question

How to create permanent PowerShell Aliases

I want to create an

of a
that doesn't expire after I close the current session of Powershell, let's say I have this alias :

C:\Users\Aymen> New-Alias Goto Set-Location

This perfectly creates the
alias, but I want to use it even after I close the current session, how can I achieve that.


The PowerShell Help system suggests that I can export the aliases I create, and import them next time I open a new session, actually that's not really what I'm looking, for, is there a direct clear way to keep having a alias after I create it through different sessions

Answer Source


Given the increasing popularity of this question here is a better answer.

It's possible to store in a profile.ps1 file any powershell code to be executed each time powershell starts. There are at least 6 different paths where to store the code depending on which user have to execute it.

So to answer your question you have only create a profile.ps1 file containing the code

New-Alias Goto Set-Location

and save it in one of the 6 available paths. The 2 most important are:

  • "$Home\Documents": put the file here to execute it only for your user.
  • $PsHome: put the file here to execute it for every user.

To apply the changes restart your powershell window.


  • If both paths contain a profile.ps1 file the all user one is executed first, then the users specific.

  • Always put the code in the user specific profile if there is no need to extend the modifications to each user. You don't need administrator rights to add the file to your user space (otherwise you do) and you don't pollute other users' space.

  • Mind that $PsHome is different between 32bit and 64bit instances of powershell, so you have to consider both environment if you want always to execute the profile code. Usually the paths are C:\Windows\System32\WindowsPowerShell\v1.0 for the 64bit environment and C:\Windows\SysWow64\WindowsPowerShell\v1.0 for the 32bit one.


You can add a file named profile.ps1 in the Powershell folder (C:\Windows\System32\WindowsPowerShell\v1.0 or C:\Windows\SysWOW64\WindowsPowerShell\v1.0) and put there the code you want to execute each time a powershell session start, like New-Alias Goto Set-Location