Could I override this command? I want to do my own job when I execute the "Get-ChildItem" command in Powershell.
Powershell – How to override the “get-childItem” command in Powershell
powershell
Related Topic
- Powershell – how to use powershell to get childitem of the parent folder and pick up the latest update child folder
- Powershell – Windows command prompt: how to get the output of a command into a environment variable
- Powershell – How to override the default dir alias in Powershell
- Iis – How to force powershell to refresh cached data? Get-ChildItem results for PSDrive not current
- PowerShell Get-ChildItem – Path Too Long
Best Answer
Yes, you can override
Get-ChildItem
or any other cmdlet in Powershell.Name Your Function The Same
If you make a function with the same name in the same scope, yours will be used.
Example:
Using Aliases
Create your own function, and then create an alias to that function, with the same name as the cmdlet you want to override.
Example:
This way is nice because it's easier to test your function without stomping on the built-in function, and you can control when the cmdlet is overridden or not within your code.
To remove the alias:
Know the Command Precedence
about_Command_Precedence lists the order in which commands of different types are interpreted: