# How to alias a directory change in Powershell?

Why does Set-Alias foo "cd C:\foo\bar\xyz\asdf\etc" not work?

foo

-> invalid format

How to do this correctly?

• you can't alias this, but you can write a function: function foo { cd "C:\users" } Jan 19, 2017 at 14:23

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

1. cmdlet
2. function
3. operable program
4. 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

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\ }