UPDATED - January 2021

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 has to execute it. We will consider only 2 of them: the "all users" and the "only your user" paths (follow the previous link for further options).

To answer your question, you only have to create a profile.ps1 file containing the code you want to be executed, that is:

New-Alias Goto Set-Location

and save it in the proper path:

  • "$Home\Documents" (usually C:\Users\<yourname>\Documents): only your user will execute the code. This is the recommended location You can quickly find your profile location by running echo $profile in PowerShell
  • $PsHome (C:\Windows\System32\WindowsPowerShell\v1.0): every user will execute this code

IMPORTANT: remember you need to restart your PowerShell instances to apply the changes.

TIPS

  • If both paths contain a profile.ps1 file, the all-users one is executed first, then the user-specific one. This means the user-specific commands will overwrite variables in case of duplicates or conflicts.

  • Always put the code in the user-specific profile if there is no need to extend its execution to every user. This is safer because you don't pollute other users' space (usually, you don't want to do that).
    Another advantage is that you don't need administrator rights to add the file to your user-space (you do for anything in C:\Windows\System32).

  • If you really need to execute the profile code for every user, mind that the $PsHome path is different for 32bit and 64bit instances of PowerShell. You should consider both environments if you want to always execute the profile code.

    The paths are:

    • C:\Windows\System32\WindowsPowerShell\v1.0 for the 64bit environment
    • C:\Windows\SysWow64\WindowsPowerShell\v1.0 for the 32bit one (Yeah I know, the folder naming is counterintuitive, but it's correct).
Answer from Naigel on Stack Overflow
Top answer
1 of 14
295

UPDATED - January 2021

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 has to execute it. We will consider only 2 of them: the "all users" and the "only your user" paths (follow the previous link for further options).

To answer your question, you only have to create a profile.ps1 file containing the code you want to be executed, that is:

New-Alias Goto Set-Location

and save it in the proper path:

  • "$Home\Documents" (usually C:\Users\<yourname>\Documents): only your user will execute the code. This is the recommended location You can quickly find your profile location by running echo $profile in PowerShell
  • $PsHome (C:\Windows\System32\WindowsPowerShell\v1.0): every user will execute this code

IMPORTANT: remember you need to restart your PowerShell instances to apply the changes.

TIPS

  • If both paths contain a profile.ps1 file, the all-users one is executed first, then the user-specific one. This means the user-specific commands will overwrite variables in case of duplicates or conflicts.

  • Always put the code in the user-specific profile if there is no need to extend its execution to every user. This is safer because you don't pollute other users' space (usually, you don't want to do that).
    Another advantage is that you don't need administrator rights to add the file to your user-space (you do for anything in C:\Windows\System32).

  • If you really need to execute the profile code for every user, mind that the $PsHome path is different for 32bit and 64bit instances of PowerShell. You should consider both environments if you want to always execute the profile code.

    The paths are:

    • C:\Windows\System32\WindowsPowerShell\v1.0 for the 64bit environment
    • C:\Windows\SysWow64\WindowsPowerShell\v1.0 for the 32bit one (Yeah I know, the folder naming is counterintuitive, but it's correct).
2 of 14
213

It's not a good idea to add this kind of thing directly to your $env:WINDIR PowerShell folders, unless you truly want your alias to be global.
The recommended way is to add it to your personal profile:

cd $env:USERPROFILE\Documents
md WindowsPowerShell -ErrorAction SilentlyContinue
cd WindowsPowerShell
New-Item Microsoft.PowerShell_profile.ps1 -ItemType "file" -ErrorAction SilentlyContinue
powershell_ise.exe .\Microsoft.PowerShell_profile.ps1

Now add your alias to the Microsoft.PowerShell_profile.ps1 file that is now opened:

function Do-ActualThing {
    # Do the actual thing
}

Set-Alias MyAlias Do-ActualThing

Then save it, and refresh the current session with:

. $profile

Note: Just in case, if you get permission issue like

CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

Try the below command and refresh the session again.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Top answer
1 of 3
3

Because WinGet is not PowerShell-specific, it cannot rely on PowerShell stuff. Instead, it does add to %PATH% (once). It also shows a message when it does this. If you did not see the message, it may have already modified %PATH% in the past. WinGet adds %LOCALAPPDATA%\Microsoft\WinGet\Links\ (in its expanded form) to your user’s %PATH% (not the system-wide one).

WinGet creates symlinks in this folder. These are then usable from any shell or Run prompt.

In my opinion, yes, this method is superior, because it is effective everywhere.

However, it only works with .exe files. If you need PowerShell-specific aliases (involving cmdlets or whatever), you must use PowerShell methods to create them permanently. $profile is the way to go.

2 of 3
2

From the post How to create permanent PowerShell Aliases, I quote the excellent answer by Naigel :

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 has to execute it. We will consider only 2 of them: the "all users" and the "only your user" paths (follow the previous link for further options).

To answer your question, you only have to create a profile.ps1 file containing the code you want to be executed, that is:

New-Alias Goto Set-Location

and save it in the proper path:

  • "$Home\Documents" (usually C:\Users\<yourname>\Documents): only your user will execute the code. This is the recommended location You can quickly find your profile location by running echo $profile in PowerShell
  • $PsHome (C:\Windows\System32\WindowsPowerShell\v1.0): every user will execute this code

IMPORTANT: remember you need to restart your PowerShell instances to apply the changes.

TIPS

  • If both paths contain a profile.ps1 file, the all-users one is executed first, then the user-specific one. This means the user-specific commands will overwrite variables in case of duplicates or conflicts.

  • Always put the code in the user-specific profile if there is no need to extend its execution to every user. This is safer because you don't pollute other users' space (usually, you don't want to do that).

  • Another advantage is that you don't need administrator rights to add the file to your user-space (you do for anything in C:\Windows\System32).

  • If you really need to execute the profile code for every user, mind that the $PsHome path is different for 32bit and 64bit instances of PowerShell. You should consider both environments if you want to always execute the profile code.

    The paths are:

  • C:\Windows\System32\WindowsPowerShell\v1.0 for the 64bit environment

  • C:\Windows\SysWow64\WindowsPowerShell\v1.0 for the 32bit one (Yeah I know, the folder naming is counter-intuitive, but it's correct).

🌐
Reddit
reddit.com › r/powershell › how to set alias permanently on windows 11 (coming from linux)
r/PowerShell on Reddit: how to set alias permanently on Windows 11 (coming from Linux)
January 1, 2025 -

I hope this is the right place to ask. Anyone know how can I set these 2 command in alias on Windows 11. In Linux it would be something like

alias sqlstart="net start postgresql-x64-16"
alias sqlstop="net stop postgresql-x64-16"

in ~/.bashrc

🌐
Medium
medium.com › @hello.ash99 › setting-up-aliases-in-powershell-1ad90ec50046
Setting up Aliases in PowerShell. Aliases are shortcuts or alternate… | by Aishwarya Mathew | Medium
June 20, 2024 - Aliases created in a session are temporary. To make them permanent, they can be added to the PowerShell profile script. The profile script runs every time you start a new PowerShell session, so add the same Set-Alias commands there.
🌐
DEV Community
dev.to › adityashrivastavv › how-to-set-permanent-and-temporary-aliases-in-powershell-and-bash-a-step-by-step-guide-1mn9
How to Set Permanent and Temporary Aliases in PowerShell and Bash: A Step-by-Step Guide - DEV Community
June 19, 2024 - ... In this example, ll is an alias for the Get-ChildItem cmdlet, which is similar to ls in Unix-based systems. ... To make an alias permanent, you need to add it to your PowerShell profile script.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › set-alias
Set-Alias (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
You can use Set-Alias to reassign an existing alias to another cmdlet, or change an alias's properties, such as the description. An alias that's created or changed by Set-Alias isn't permanent and is only available during the current PowerShell ...
🌐
GitHub
gist.github.com › mrgarymartin › d2c296bb6ac019d59009c38f745eec9e
Create a permanent Powershell Alias Profile · GitHub
Create a permanent Powershell Alias Profile · Raw · readme.md · Make the document user profile · cd $env:USERPROFILE\Documents md WindowsPowerShell -ErrorAction SilentlyContinue New-Item -Path $Profile -Type File · Using a function the contents of Microsoft.PowerShell_profile.ps1 can be: function Do-ActualThing { # do actual thing } Set-Alias MyAlias Do-ActualThing ·
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell aliases: a beginner’s guide
PowerShell Aliases: A Beginner's Guide - SharePoint Diary
October 3, 2025 - By default, any alias you create ... you open PowerShell. If you want to make the Alias permanent, you need to Add Alias to the PowerShell profile....
Find elsewhere
🌐
PDQ
pdq.com › powershell › set-alias
Set-Alias - PowerShell Command | PDQ
You can also use Set-Alias to reassign a current alias to a new command, or to change any of the properties of an alias, such as its description. Unless you add the alias to the Windows PowerShell profile, the changes to an alias are lost when you exit the session or close Windows PowerShell.
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-powershell-alias-permanently
How to create PowerShell alias permanently?
February 14, 2020 - PowerShell alias can be created permanently by 2 methods below. To export all the aliases, you need to use Export-Alias cmdlet. When you use this command it will ask you the path for the file to import.
🌐
ScriptRunner
scriptrunner.com › blog-admin-architect › powershell-aliasing
PowerShell Aliasing | ScriptRunner Blog
March 20, 2025 - Everything we did up to now will vanish once you close your current PowerShell session, as setting aliases is not a permanent operation.
🌐
Linux Hint
linuxhint.com › create-powershell-alias
How to Create PowerShell Alias
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
ShellGeek
shellgeek.com › home › powershell › set alias permanent in powershell
Set Alias Permanent in PowerShell - ShellGeek
April 14, 2024 - However, created or set alias information is available for the current session or till you close PowerShell. Hence, to save alias permanently in PowerShell, use Export-Alias and Import-Alias cmdlets.
🌐
Seb Nilsson
sebnilsson.com › blog › powershell-profile-with-permanent-aliases
PowerShell Profile with Permanent Aliases - Seb Nilsson
September 17, 2014 - If you're a PowerShell-user who manually runs scripts or binds an alias every time you open PowerShell, then there is a file you really should know about. It's...
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › new-alias
New-Alias (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
PowerShell includes the following aliases for New-Alias: ... To create a new alias, use Set-Alias or New-Alias. To change an alias, use Set-Alias.
🌐
Medium
ahnashwin1305.medium.com › setting-up-permanent-alias-in-windows-powershell-8d30e81ed7e9
Setting up permanent alias in Windows PowerShell. | by Ashwin B | Medium
March 12, 2024 - 2. Now create a folder with the exact name “WindowsPowerShell” and inside it create a file called “Microsoft.PowerShell_profile.ps1” in the location to which the “value” variable points us. ... 3. We are about to do the magical step now. Now it’s time to create a new alias command by inputting the following Set-Alias <name> <value>. Replace the name with the new name that you want to call and value with the actual value that needs to be executed.
🌐
Powershelltutorial
powershelltutorial.net › PS-Script › creating-persistent-aliases-in-powershell.aspx
Powershell Tutorial - Creating Persistent Aliases in PowerShell
Making a permanent alias is helpful and far more efficient. The best part about it is that all of this can be done by defining aliases in your profile script. Since the profile is executed every time you open a new PSH window, it's the perfect location to define your aliases of choice so they're immediately available to you the moment you open up PSH. There are two commands that PSH has that will assist in making the aliases persistent.
🌐
SS64
ss64.com › ps › set-alias.html
Set-Alias - PowerShell cmdlet
The 'built-in' aliases supplied with PowerShell have the option AllScope set, so they will survive any changes in scope. The 'built-in' aliases that are idiomatic to PowerShell also have the ReadOnly option set.
🌐
Medium
frankie95.medium.com › set-alias-command-in-powershell-to-make-your-life-easier-61de600c18d2
Set alias command in powershell to make your life easier | by Frankie | Medium
December 2, 2020 - notepad) to open Microsoft.PowerShell_profile.ps1 · Create new alias command by inputting Set-Alias <name> <value>.