powershell-gci排除父文件夹包含TECH的目录和子目录?

问题描述 投票:0回答:1

排除排除父目录下的目录和所有子目录时遇到麻烦。我运行此文件,但需要排除以TECH开头或路径中包含的目录和子目录。

 c:\users\user1
         user2
         tech-xxx  (random numbers - need to exclude this and all subdirectories)
         tech-xxx  (random numbers - need to exclude this and all subdirectories)

这些失败(以及我尝试过的许多其他变体):

$UserDirExtensions="*.cmd","*.bat"
gci C:\Users -Recurse -Include $UserDirExtensions | Where-Object {!($_.FullName -icontains 'tech*') 

$Folders = (gci C:\Users -Directory | Select-Object -Property name | Where {$_.Name -notlike 'tech*' })
foreach ($i in $Folders) {
    gci C:\Users\$i -Recurse -Include $UserDirExtensions
    }

预先感谢。

powershell get-childitem
1个回答
0
投票

名称不是全名。 -contains不会执行您想的,它基本上匹配数组中的整个单词。

dir -r | where fullname -notlike *tech*

有几种方法可以专注于父级,但这不会排除技术文件夹本身:

dir -r | where psparentpath -notlike *tech*
dir -r | where directory -notlike *tech*
dir -r | where directoryname -notlike *tech*
© www.soinside.com 2019 - 2024. All rights reserved.