I need to generate a configuration file for our Pro/Engineer CAD system. I need a recursive list of the folders from a particular drive on our server. However I need to EXCL
I wanted a solution that didn't involve looping over every single item and doing if
s. Here's a solution that is just a simple recursive function over Get-ChildItem
. We just loop and recurse over directories.
function Get-RecurseItem {
[Cmdletbinding()]
param (
[Parameter(ValueFromPipeline=$true)][string]$Path,
[string[]]$Exclude = @(),
[string]$Include = '*'
)
Get-ChildItem -Path (Join-Path $Path '*') -Exclude $Exclude -Directory | ForEach-Object {
@(Get-ChildItem -Path (Join-Path $_ '*') -Include $Include -Exclude $Exclude -File) + ``
@(Get-RecurseItem -Path $_ -Include $Include -Exclude $Exclude)
}
}