Question:
I wish Get-ChildItem -force
to get executed when I type ll
and I have this in my profile.ps1
:
1 2 |
New-Alias -Name ll -Value Get-ChildItem -force |
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
.
Answer:
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:
1 2 3 4 |
function ll { Get-ChildItem -Force @args } |
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
).