How can I exclude multiple folders using Get-ChildItem -exclude?

前端 未结 12 935
星月不相逢
星月不相逢 2020-11-27 16:19

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

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:50

    I wanted a solution that didn't involve looping over every single item and doing ifs. 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)
        }
    }
    

提交回复
热议问题