Recursive -Verbose in Powershell

Question:

Is there an easy way to make the -Verbose switch “passthrough” to other function calls in Powershell?

I know I can probably search $PSBoundParameters for the flag and do an if statement:

It seems rather messy and redundant to do it this way however… Thoughts?

Answer:

One way is to use $PSDefaultParameters at the top of your advanced function:

Then every command you invoke with a -Verbose parameter will have it set depending on whether or not you used -Verbose when you invoked your advanced function.

If you have just a few commands the do this:

Source:

Recursive -Verbose in Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply