PowerShell alias syntax for running a cmd.exe builtin function?

风格不统一 提交于 2019-12-06 12:09:39

I believe what you want is a function, not an alias. For instance:

  function dirb {
    cmd /c dir $args[0] /b
     }

From a PS prompt, run notepad $profile, paste that into your profile and then it will load automatically when you open a PS console and you can do this:

dirb c:\somedir

See get-help about_functions for more information about functions.

Aliases are not designed for this kind of tasks. An alias is just another name of a command. Use the function instead.

function dirb { cmd /c dir /b }

Aliases in powershell don't take parameters unfortunately - you need to define a function for this. For more info,

get-help aliases

Why on earth would you use powershell to open the command prompt? That seems to be defeating the purpose.

The Alias I prefer to list out files is simply ls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!