To get a permanent alias, put it in your personal profile file. (There are other global profiles files but aliases are personal preferences.) The profile is a script that is run every time you start PowerShell, unless you specify a noprofile flag on the command line. It can be used to set aliases and variables, load functions and libraries, set the start location, and do anything else you might do to make your environment work the way you like it.
The path of the profile is given in the $profile variable. If you have not created a profile, it usually won't exist, but the profile variable will exist. You can edit the profile file from the PS prompt like this
notepad.exe $profile
You will probably get an error because the the path to the file is not there. Use this command to create the full path and the file the first time.
New-Item -path $profile -ItemType File -Force # WARNING: This will overwrite!
Now edit your profile using notepad as above. After updating and saving your profile, you can dot run it to reload it and test the change without restarting PowerShell.
. $profile
Most things that go in the profile can be done repeatedly but if a repeat run breaks anything, add a test.
Bonus: One of the things I love in my profile is an alias to my preferred quick text editor so I can avoid notepad. I also generally add one line comment/reminder message when I do stuff in the profile:
'Notepad++ alias:npp'
Set-Alias -Name 'npp' -value 'C:\Program Files\Notepad++\notepad++.exe'
Going one step closer to full OCD, you could add a function in your profile to update your profile and reload it. (I'm not OCD, this is an example.)
'Profile updater, alias pup'
function Update-Profile {
npp $profile
pause
. $profile
}
Set-Alias -Name 'pup' -Value 'Update-Profile'
echo "Set-Alias bun pnpm" >> $profile && . $profile
, full answer somewhere below.