How to alias a directory change in Powershell?
Solution 1
IMHO, You cannot alias a cmdlet-and-a-variable into an alias name.
I mean it is valid if you write Set-Alias foo cd
but
it is not valid to write Set-Alias foo cd C:\Users
See the example image below for better understanding.
The error clearly says
Cannot resolve alias 'foo' because it refers to term 'cd C:\Users' which is not recognized as a cmdlet, function, operable program or script file
So Set-Alias
command is expecting only four of the following to be aliased
- cmdlet
- function
- operable program
- script file.
The path C:\Users
does not qualify as one.
You can write a script file (*.ps1) and get this done through alias
Use the get-alias
command to see the list of aliases that have been set in the system.
Use Remove-item
command to reset the alias that have been set.
Reference
Solution 2
make a function inside profile.ps1 (function name uppercase)
https://stackoverflow.com/questions/24914589/how-to-create-permanent-powershell-aliases
eg. function Mesa{ cd $home\Desktop\ }
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
Why does
Set-Alias foo "cd C:\foo\bar\xyz\asdf\etc"
not work?foo
-> invalid format
How to do this correctly?