Hello,
We have a powershell file ‘function.ps1’ with many custom functions. And many scripts use these functions from this file. I want to rewrite/improve and rename all functions. But I don’t want to change all individual scripts at once. I want the old function to redirect it to the new function. Some functions have 1 argument and some 5 arguments and I want a simple uniform way to redirect the arguments to the new function.
Example:
This is what we have.
function writelog($file,$text) {
old-code
}
function custom-writelog($file,$text) {
new-code
}
This is what I want (but this doesn ́t work)
function writelog() {
custom-writelog $args
}
function custom-writelog($file,$text) {
new-code
}
I now use this, but is this the best way?
function writelog() {
switch ($args.count) {
1 { custom-writelog $args[0] }
2 { custom-writelog $args[0] $args[1] }
3 { custom-writelog $args[0] $args[1] $args[2] }
4 { custom-writelog $args[0] $args[1] $args[2] $args[3] }
5 { custom-writelog $args[0] $args[1] $args[2] $args[3] $args[4] }
6 { custom-writelog $args[0] $args[1] $args[2] $args[3] $args[4] $args[5] }
}
}
Bert