You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询MS Graph API getSharePointSiteUsageDetail是否支持自定义报告周期

解决方案:自定义SharePoint站点使用报告周期

首先明确:getSharePointSiteUsageDetail 这个MS Graph API端点不支持通过startDate和endDate参数自定义时间段,它仅接受预定义的period参数值:D7(最近7天)、D30(最近30天)、D90(最近90天)、D180(最近180天),这就是你之前调用带startDate/endDate的接口无效的原因。

以下是可行的替代方案:

方案一:获取长周期数据后本地过滤

调用覆盖目标时间段的最长可用周期接口,获取全量数据后,在PowerShell中筛选指定日期范围的记录:

# 1. 调用D180周期接口获取最近180天的详细数据(需先完成身份验证,如Connect-MgGraph)
$reportUri = "https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageDetail(period='D180')"
$reportResponse = Invoke-MgGraphRequest -Uri $reportUri -Method Get

# 2. 将CSV格式的响应内容转换为PowerShell对象
$siteUsageData = $reportResponse.Content | ConvertFrom-Csv

# 3. 过滤2023-03-10至2023-04-10的记录
# 注意:字段名需匹配你的租户报告语言,中文租户可能是「报告日期」,英文租户为「ReportDate」
$filteredData = $siteUsageData | Where-Object {
    [DateTime]$_.ReportDate -ge [DateTime]"2023-03-10" -and
    [DateTime]$_.ReportDate -le [DateTime]"2023-04-10"
}

# 4. 导出过滤后的数据到CSV文件
$filteredData | Export-Csv -Path "CustomRangeSharePointUsage.csv" -NoTypeInformation

方案二:使用Microsoft Graph PowerShell模块简化调用

如果使用Microsoft Graph PowerShell模块,可直接用专用命令获取数据,再执行本地过滤:

# 确保已安装并连接模块
# Install-Module Microsoft.Graph.Reports
# Connect-MgGraph -Scopes Reports.Read.All

# 获取D180周期的报告数据
$siteUsageReport = Get-MgReportSharePointSiteUsageDetail -Period D180

# 转换为可筛选的对象并过滤时间范围
$filteredReport = $siteUsageReport | Where-Object {
    [DateTime]$_.ReportDate -ge [DateTime]"2023-03-10" -and
    [DateTime]$_.ReportDate -le [DateTime]"2023-04-10"
}

注意事项

  • 微软仅保留最近180天的SharePoint站点使用详细报告数据,无法通过该API获取更早的历史记录;
  • 若需要定期获取自定义范围的数据,建议设置定时任务,定期导出并存储全量D180数据,方便后续回溯查询。

内容的提问来源于stack exchange,提问作者Pret19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 05:35:25