powershell - 使用powershell v2分配给递归gci搜索省略文件夹时没有返回变量
问题描述
我正在尝试递归搜索 Windows 7 机器上的文件 + 连接到它的网络驱动器,同时排除某些文件夹,即 C:\windows 和其中的所有递归文件夹,例如 system32。
我知道之前有人问过这个问题,但遵循答案并没有帮助,我仍然留下一个空白变量。
以下是我尝试过的组合:
$AllDrives = Get-PSDrive
$files=@("*.xml",*.txt)
foreach ($Drive in $AllDrives) {
if ($Drive.Provider.Name -eq "FileSystem") {
$filenames = Get-ChildItem -recurse $drive.root -include ($files) -File | Where-Object {$_.PSParentPath -notlike "*Windows*" -and $_.PSParentPath -notlike "*Microsoft*"
}
}
我也尝试过这些组合:
$filenames = Get-ChildItem -recurse $drive.root -include ($files) -File | Where-Object {$_.PSParentPath -notmatch "Program Files|Users|Windows"}
$exclude_pattern = $drive.root + "Windows"
$filenames = Get-ChildItem -Force -Recurse -path $drive.root -Include $files -Attributes !Directory+!System -ErrorAction "SilentlyContinue" | Where-Object { $_.PSIsContainer -eq $false } | Where-Object { $_.FullName -notmatch $exclude_pattern }
不幸的是,经过一段时间后,当我$filename
在终端中输入时,没有任何分配给它。
解决方案
推荐阅读
- java - 尝试在 mac 中运行任何 android sdk 工具(如 sdkmanager、avdmanager 等)时出错
- java - @Transactional proxyTargetClass 和 @Inherited
- python - ec2实例上的python gearman worker没有响应
- javascript - Javascript 复制 div 文本并拆分为输入
- mysql - Perl TLS1.2 到 MySql Db
- c - Xplained pro SAM4SD32C - 定时器 1 - 无法写入 RA 寄存器
- php - 如何获取当年 SQL 中每个月的计数?
- javascript - 循环数组,并添加值以启动 Javascript
- android - SQLite 不能使用某些表名?
- sql-server - 在 SSRS 中传递参数以插入 SQL Server 查询以更新表