I am working on a exciting book review from a good friend and one of my thoughts is that , when applicable, we can use the verbose from the own cmdlet .
I always thought that if you pass a –verbose parameter to an advanced function , it is recursive to the other cmdlets inside it. Well, I can be wrong, but my test said that is not what happens .
My point is ,lets say that you have a function to copy files from a path to other. (of course you don’t need a function for this, but just to illustrate) you don’t need to write-verbose “Copying…..”…You can use the verbose message from the copy-item
You can see that I am testing if the –verbose parameter was passed and if the $verbosepreference variable was change :
Then it is just pass the $verbose variable to the cmdlet : –Verbose:$verbose
Now it is just to call using verbose :
or not using verbose :
or you just can change the $verbosepreference before the calling the function , put –verbose in the copy-item, or just use write-verbose and you will not to worry about this code that I did. But I liked to do this and avoiding to change the variable or use write-verbose. Just another approach maybe.
I confess that I DO need to do more test,but so far that is what I figured out