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

如何将PowerShell提取的Power Automate流运行记录同步至Power Apps画布应用?

Power Apps画布应用中点击「全部运行」仅能获取Power Automate流28天内的运行历史:

示例「全部运行」

已经通过PowerShell提取到全量流运行记录,以下是将这些数据同步到Power Apps的可行方案:

方案1:通过Dataverse存储全量运行记录(推荐)
  • 步骤1:在Dataverse中创建自定义表,字段对应PowerShell提取的流运行属性,比如流名称、运行ID、开始时间、运行状态、触发源、错误详情等。
  • 步骤2:修改PowerShell脚本,将提取到的运行记录批量写入Dataverse表。可以用Invoke-PowerRestMethod调用Dataverse Web API完成写入:
# 假设$flowRuns是已提取的全量运行记录数组
# 先获取Dataverse授权头(需提前完成身份验证)
$authHeaders = @{
    "Authorization" = "Bearer $accessToken"
    "Content-Type" = "application/json"
}

foreach ($run in $flowRuns) {
    $record = @{
        "crbcf_flowname" = $run.FlowName  # 替换为你Dataverse表的字段名
        "crbcf_runid" = $run.RunId
        "crbcf_starttime" = $run.StartTime
        "crbcf_status" = $run.Status
        # 按需添加其他字段
    }
    Invoke-PowerRestMethod -Method Post -Url "https://yourorg.crm.dynamics.com/api/data/v9.2/crbc_flowruns" -Body ($record | ConvertTo-Json) -Headers $authHeaders
}
  • 步骤3:在Power Apps画布应用中添加该Dataverse表作为数据源,即可直接查看全量流运行记录,还能添加筛选、排序、搜索等自定义功能。
方案2:通过SharePoint列表作为中间存储
  • 步骤1:创建SharePoint列表,配置字段匹配流运行记录的关键信息(比如单行文本存流名称、日期时间类型存开始时间、选择列存运行状态等)。
  • 步骤2:修改PowerShell脚本,用PnP.PowerShell模块将记录写入SharePoint列表:
# 连接到目标SharePoint站点
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive

# 遍历运行记录写入列表
foreach ($run in $flowRuns) {
    Add-PnPListItem -List "Flow运行记录" -Values @{
        "Title" = $run.FlowName
        "RunID" = $run.RunId
        "StartTime" = $run.StartTime
        "Status" = $run.Status
    }
}
  • 步骤3:在Power Apps中添加该SharePoint列表作为数据源,即可在应用内展示全量运行记录,支持自定义视图和操作。
方案3:通过Power Automate中转实现定时同步
  • 步骤1:创建一个Power Automate手动触发流,添加「HTTP请求」触发器,设置请求体格式为JSON,匹配流运行记录的字段。
  • 步骤2:在PowerShell脚本中,将提取的运行记录转为JSON,通过Invoke-RestMethod发送到Power Automate的触发URL:
$flowTriggerUrl = "https://prod-xx.westus.logic.azure.com:443/workflows/xxxx/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=xxxx"
$body = $flowRuns | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method Post -Uri $flowTriggerUrl -Body $body -ContentType "application/json"
  • 步骤3:在Power Automate流中,将接收到的数据写入Dataverse或SharePoint列表(同前两个方案的存储方式)。如果需要定期同步全量记录,可设置Windows任务计划,定时运行PowerShell脚本更新数据。

内容的提问来源于stack exchange,提问作者Mohamed Amine Trigui

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 04:08:09