How to supply argument to value of New-Alias command?


I wish Get-ChildItem -force to get executed when I type ll and I have this in my profile.ps1:

However, when I type ll, I can see that the -force argument is not being used. What am I doing wrong?

Edit: What I really wish to achieve is to show all files in a folder, even if they’re hidden. And I wish to bind this to ll.


You cannot do that with aliases. Aliases are really just different names for commands, they cannot include arguments.

What you can do, however, is, write a function instead of using an alias:

You won’t get tab completion for arguments in that case, though, as the function doesn’t advertise any parameters (even though all parameters of Get-ChildItem get passed through and work). You can solve that by effectively replicating all parameters of Get-ChildItem for the function, akin to how PowerShell’s own help function is written (you can examine its source code via Get-Content Function:help).


How to supply argument to value of New-Alias command? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply