I was recently in a position where I was asked to provide an example of a PowerShell recursive function. Unfortunately, I didn't have time to do that as it was a part of a written, and timed test. Sadly, I didn't even really have time to review the other 50-some answers I had already provided. I mostly knew that might happen.
Anyway, the challenge has been eating at me, so why not write an example and share it. It'll be good for you, as it will be for me too. It's out there, but it's not often utilized that I'm aware. A recursive function is a function that calls, or invokes, itself. For real. We're not referring to a function, or cmdlet, that includes a Recurse parameter. Now that said, it's possible that some of these commands, with that parameter do this (call themselves), but I've yet to take a look to see for sure.
After you see today's example, you'll begin to understand why you might prefer to do things this way. If you can wrap your head around the concept, you'll understand that it can reduce a portion of code writing on your part. Join me at https://tommymaynard.com to finish this article. Here's the direct link.
≥ Tommy Maynard (Twitter: @thetommymaynard)