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


-> invalid format

How to do this correctly?

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

2 Answers 2


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
it is not valid to write Set-Alias foo cd C:\Users
See the example image below for better understanding.
enter image description here

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.


make a function inside profile.ps1 (function name uppercase)


eg. function Mesa{ cd $home\Desktop\ }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.