Honestly, I would avoid doing it this way. My suggestions, in no particular order:
- Don't use $args--it's so easy to do named params in powershell which are vastly superior
- Remember GIGO. If you pass $null's into the add function, then $null is what you get out!
- Why not move your entire Params() block to the first line of the script (and remove the last line)? That will make it behave as you think it would.
- To make it work like you want, with the logic exactly as you want, then you would need to perform tests to see if there are $args and if so, do it this way and if not, call the function w/o any params, which would allow those defaults to kick in. e.g.
if ( $args ) { add $args[ 0 ] $args [ 1 ] }
else { add } But again--I wouldn't use $args because I've totally written them off. :)
P.S., the forum software doesn't like bracket-number-bracket for some reason. Inserting a space is a workaround until we get that fixed.