You can also run the process section within the function. It would look like this:
Function Do-Stuff {
param(
[Parameter( `
Mandatory=$True, `
Valuefrompipeline = $true)]
[String]$Folders
)
begin {
#Things to do only once, before processing
} #End Begin
Process {
#What you want to do with each item in $Folders
} #End Process
end {
#Things to do at the end of the function, after all processes are done
}#End end
} #End Function Do-Stuff
Then when you call the Function. Do it like this
$Folders | Do-Stuff
Here is what will happen. Everything in the Begin block will run first. Then, for each item in the $Folders variable, everything in the Process block will run. After it completes that, it will run what is in the End block. This way you can pipe as many folders as you want into your function. This is really helpful if you want to add additional parameters to this function some day.