Get-MgDriveItemChild无法筛选文件/文件夹问题求助
解决Get-MgDriveItemChild无法筛选排除文件夹的问题
问题说明
使用Microsoft.Graph.Files模块1.10.0版本的Get-MgDriveItemChild命令时,尝试两种常规筛选方式均无法排除文件夹:
# 本地过滤无效 $subitems = Get-MgDriveItemChild -DriveId $drive.id -DriveItemId $targetItem.id -All $files = $subitems | Where-Object { $_.folder -eq $null } # 服务器端Filter参数无效 $subitems = Get-MgDriveItemChild -DriveId $drive.id -DriveItemId $targetItem.id -All -Filter 'Folder eq null'
经确认这是当前模块的已知未修复bug。
替代解决方案
可利用Graph API中文件与文件夹的属性差异(文件会携带file复合属性,文件夹无此属性),通过反向判断属性存在性来筛选文件:
本地过滤方案
$subitems = Get-MgDriveItemChild -DriveId $drive.id -DriveItemId $targetItem.id -All $files = $subitems | Where-Object { $null -ne $_.file }
服务器端过滤方案(若模块支持)
尝试通过判断file属性非空来直接在服务器端筛选:
$files = Get-MgDriveItemChild -DriveId $drive.id -DriveItemId $targetItem.id -All -Filter 'file ne null'
备注
若服务器端过滤仍无效,优先采用本地过滤方案。该方法通过区分文件特有的file属性来规避folder属性判断的bug。
内容的提问来源于stack exchange,提问作者Mark Lord
相关产品推荐
相关产品推荐

