使用Where筛选时PowerShell Get-ComplianceSearch的Items与Size值为0
问题原因与解决方法
问题根因
Get-ComplianceSearch不带-Identity参数批量查询时,返回的是简化的摘要对象,仅包含任务名称、状态等基础属性,不会自动加载任务运行后的统计数据(Items、Size这类字段)。只有通过-Identity指定单个任务时,才会从Microsoft Purview后端拉取该任务的完整详情,包括实际的搜索结果统计值。
解决方法
通过循环逐个查询符合条件的任务,来获取完整的Items和Size数据:
# 先筛选出目标任务集合 $targetSearches = Get-ComplianceSearch | Where-Object { $_.Name -like 'Spam Emails*' } # 循环遍历每个任务,获取完整统计数据 foreach ($search in $targetSearches) { Get-ComplianceSearch -Identity $search.Identity | Select-Object Name, Items, Size }
如果需要导出结果到文件方便查看,可以用下面的脚本:
$results = @() foreach ($search in $targetSearches) { $fullSearch = Get-ComplianceSearch -Identity $search.Identity $results += [PSCustomObject]@{ Name = $fullSearch.Name Items = $fullSearch.Items Size = $fullSearch.Size } } $results | Export-Csv -Path "SpamSearchResults.csv" -NoTypeInformation
内容的提问来源于stack exchange,提问作者ADY
相关产品推荐
相关产品推荐

