I am relatively new to PowerShell, so I am hoping this is simple, and I just missed it. I am looking to create a function that could toggle the ability to recurse in get-childItem.
As a very basic example:
...
param
(
[string] $sourceDirectory = ".",
[string] $fileTypeFilter = "*.log",
[boolean] $recurse = $true
)
get-childitem $sourceDirectory -recurse -filter $fileTypeFilter |
...
How does one conditionally add the -recurse flag to get-childItem without having to resort to some if/else statement? I thought perhaps one could just substitute the -recurse in the get-childitem statement with a $recurseText parameter (set to "-recurse" if $recurse were true), but that does not seem to work.