排除排除父目录下的目录和所有子目录时遇到麻烦。我运行此文件,但需要排除以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
}
预先感谢。
名称不是全名。 -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*