Is it possible to set default values for existing commands in PowerShell?
What I specifically want to do is to tell the Get-ChildItem
command to show both normal and hidden files (Get-ChildItem -Force
).
I know I can write a function where I can add this option and use whatever else is specified on the command line. But then I lose the auto-completion functionality for all parameters and options.
CodePudding user response:
You should be able to do so using $PSDefaultParameterValues
. Has worked from 3.0 .
Microsoft's documentation:
Here is a set of examples directly from that documentation:
$PSDefaultParameterValues=@{"CmdletName:ParameterName"="DefaultValue"}
$PSDefaultParameterValues=@{ "CmdletName:ParameterName"={{ScriptBlock}} }
$PSDefaultParameterValues["Disabled"]=$True | $False