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
🌐
PDQ
pdq.com › powershell › set-alias
Set-Alias - PowerShell Command | PDQ
To create a profile in the path stored in the $profile variable, type `New-Item -Type file -Force $profile`. To see the value of the $profile variable, type `$profile`. * You can also save your aliases by using Export-Alias to copy the aliases from the session to a file, and then use Import-Alias to add them to the alias list for a new session. You can also refer to Set-Alias by its built-in alias, sal *. For more information, see about_Aliases. This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.PowerShell Commands
🌐
GitHub
github.com › hackf5 › powershell-profile-alias
GitHub - hackf5/powershell-profile-alias: Bash style aliases in PowerShell · GitHub
Haven't you ever wanted to write bash aliases in PowerShell? You know, like all the cool kids do on their overpriced Mac books with the stickers on them that say things like Reagan Bush '84? ... > Set-ProfileAlias laws -Command (-join( 'docker run --network crypto_crypto-net --rm -it ', '-v $env:userprofile\.aws\\localstack:/root/.aws amazon/aws-cli ', '--endpoint-url=http://localstack:4566 #{*}')) -Bash > laws sqs list-queues QueueUrls: - http://localhost:4566/000000000000/my_queue - http://localhost:4566/000000000000/queue1
Starred by 49 users
Forked by 3 users
Languages   PowerShell
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).

🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › set-alias
Set-Alias (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
The Set-Alias cmdlet creates an alias in the current PowerShell session. The Name parameter specifies the alias's name, loc. The Value parameter specifies the Get-Location cmdlet that the alias runs.
🌐
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 - To make an alias permanent, you need to add it to your shell's configuration file, such as .bashrc or .bash_profile. ... Open a terminal. Open your .bashrc file in a text editor. You can do this with nano or vi ... Save and close the text editor. ... Setting aliases in PowerShell and Bash can greatly enhance your productivity by reducing the amount of typing required for frequently used commands.
Find elsewhere
🌐
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 - You can use the “notepad $PROFILE” command to open it in Notepad. Add the “Set-Alias” command to create your Alias. For example: ... Save and close the file. Restart PowerShell.
🌐
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 - Open your PowerShell profile in a text editor. If the profile doesn’t exist, create it: ... Set-Alias -Name mkstart -Value "minikube start" Set-Alias -Name mkprofls -Value "minikube profile list" Set-Alias -Name mkprof -Value "minikube start --profile="
🌐
Seb Nilsson
sebnilsson.com › blog › powershell-profile-with-permanent-aliases
PowerShell Profile with Permanent Aliases - Seb Nilsson
September 17, 2014 - %UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 · When you've ensured that this file is created you can enter PowerShell-scripts that will run every time you open your PowerShell-console. Ensure that your execution policy is configured to support this: ... For example you can create a PowerShell-alias for the git-command to work with just using g instead:
🌐
Notoriousrebel
notoriousrebel.github.io › 2019-11-24-using-and-abusing-aliases-with-powershell
Using and Abusing Aliases with PowerShell
November 24, 2019 - Back to our favorite example with ls we saw that it was aliased to Get-ChildItem so lets try redefining what Get-ChildItem is: Get-ChildItem has been redefined to spawn a powershell session that simply calls Get-ChildItem. PowerShell is called with the flag -nop short for NoProfile as to not load profiles...
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-powershell-alias-permanently
How to create PowerShell alias permanently?
February 14, 2020 - Here, we will create a profile file Profile.ps1 using below command on the $PROFILE path of your PowerShell. notepad $((Split-Path $profile -Parent) + "\profile.ps1") The above command will prompt to the user to create Profile1.ps1 on the $Profile path if it doesn’t exist and if it is already created then it will open the file to allow the user to manipulate. Once a file is opened, edit the file to set your aliases.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_aliases
about_Aliases - PowerShell | Microsoft Learn
Describes how to use alternate names for cmdlets and commands in PowerShell. An alias is an alternate name or nickname for a cmdlet or for a command element, such as a function, script, file, or executable file.
🌐
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

🌐
Baldbeardedbuilder
baldbeardedbuilder.com › blog › adding-command-aliases-to-power-shell
Adding command aliases to Powershell
I’m not going to go into detail on how to write PowerShell functions or options for parameters. There are plenty of resources out there for the two. But hopefully this showed you a rudimentary way to set up command aliases for PowerShell. Just add the code to your PowerShell profile.ps1 and ...
🌐
ServerWatch
serverwatch.com › home › guides
PowerShell Aliases | Create Alias for PowerShell cmdlet
March 12, 2021 - What you can do to prevent these errors is use “Set-Alias” instead of using the “New-Alias” PowerShell cmdlet and then follow the below steps to ensure that Aliases remain active when you open a new PowerShell window or when a PowerShell script runs that uses Aliases: Create a PSConfiguration folder in your Windows PowerShell profile.
🌐
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>.
🌐
GitHub
gist.github.com › mrgarymartin › d2c296bb6ac019d59009c38f745eec9e
Create a permanent Powershell Alias Profile · GitHub
Using a function the contents of Microsoft.PowerShell_profile.ps1 can be: function Do-ActualThing { # do actual thing } Set-Alias MyAlias Do-ActualThing
🌐
4sysops
4sysops.com › home › blog › powershell tutoiral › how to create a powershell alias
How to create a PowerShell alias – 4sysops
July 28, 2023 - In order of appearance, these aliases display eventlog errors per day, last boot time of a machine, PowerShell version, and, finally, two deployment values: machine serial number and machine model from the BIOS, respectively. You can, of course, split your aliases off into a separate file altogether if you want, using Export-Alias, and simply have “import-alias D:\youraliases.txt” in your profile.