# Autopilot status report - Power Automate steps for your existing Inventory list This version assumes your SharePoint list uses these real columns: - Title = serial number - DeviceName - Stage - OverallState - LastUpdatedUtc - TeamsMessageId ## Step 1 - Trigger Action: **When a Teams webhook request is received** Schema: ```json { "type": "object", "properties": { "secret": { "type": "string" }, "deviceName": { "type": "string" }, "serialNumber": { "type": "string" }, "timeUtc": { "type": "string" }, "stage": { "type": "string" }, "overallState": { "type": "string" }, "counts": { "type": "object", "properties": { "total": { "type": "integer" }, "pending": { "type": "integer" }, "inProgress": { "type": "integer" }, "complete": { "type": "integer" }, "notRequired": { "type": "integer" }, "error": { "type": "integer" } } }, "topErrors": { "type": "array", "items": { "type": "string" } }, "topTrackingItems": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "state": { "type": "string" } } } } }, "required": [ "secret", "deviceName", "serialNumber", "timeUtc", "stage", "overallState", "counts" ] } ``` ## Step 2 - Validate secret Action: **Condition** Rename: `Validate_Secret` Expression: ```text @equals(triggerBody()?['secret'], 'hemlig-secret') ``` ### If No Action: **Terminate** - Status: `Failed` - Code: `InvalidSecret` - Message: `Invalid secret` ### If Yes Continue. ## Step 3 - Get existing item Action: **SharePoint - Get items** Rename: `Get_items` - Site Address: your site - List Name: `Inventory` - Filter Query: ```text Title eq '@{triggerBody()?['serialNumber']}' ``` - Top Count: ```text 1 ``` ## Step 4 - Check if serial exists Action: **Condition** Rename: `Serial_Exists` Expression: ```text @greater(length(body('Get_items')?['value']), 0) ``` --- ## If Yes branch ### Step 5 - Update existing SharePoint item Action: **SharePoint - Update item** Rename: `Update_item` - Id ```text @first(body('Get_items')?['value'])?['ID'] ``` - Title ```text @triggerBody()?['serialNumber'] ``` - DeviceName ```text @triggerBody()?['deviceName'] ``` - Stage ```text @triggerBody()?['stage'] ``` - OverallState ```text @triggerBody()?['overallState'] ``` - LastUpdatedUtc ```text @triggerBody()?['timeUtc'] ``` - TeamsMessageId ```text @first(body('Get_items')?['value'])?['TeamsMessageId'] ``` --- ## If No branch ### Step 6 - Create new SharePoint item Action: **SharePoint - Create item** Rename: `Create_item` - Title ```text @triggerBody()?['serialNumber'] ``` - DeviceName ```text @triggerBody()?['deviceName'] ``` - Stage ```text @triggerBody()?['stage'] ``` - OverallState ```text @triggerBody()?['overallState'] ``` - LastUpdatedUtc ```text @triggerBody()?['timeUtc'] ``` ### Step 7 - Compose adaptive card JSON Action: **Compose** Rename: `CardJson` ```json { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.5", "body": [ { "type": "TextBlock", "size": "Large", "weight": "Bolder", "wrap": true, "text": "Intune / Autopilot deployment status" }, { "type": "TextBlock", "spacing": "None", "isSubtle": true, "wrap": true, "text": "Device: @{triggerBody()?['deviceName']} • Serial: @{triggerBody()?['serialNumber']}" }, { "type": "TextBlock", "spacing": "None", "isSubtle": true, "wrap": true, "text": "Last update (UTC): @{triggerBody()?['timeUtc']}" }, { "type": "FactSet", "spacing": "Medium", "facts": [ { "title": "Stage", "value": "@{triggerBody()?['stage']}" }, { "title": "Overall", "value": "@{triggerBody()?['overallState']}" }, { "title": "Total", "value": "@{triggerBody()?['counts']?['total']}" }, { "title": "Pending", "value": "@{triggerBody()?['counts']?['pending']}" }, { "title": "In progress", "value": "@{triggerBody()?['counts']?['inProgress']}" }, { "title": "Complete", "value": "@{triggerBody()?['counts']?['complete']}" }, { "title": "Error", "value": "@{triggerBody()?['counts']?['error']}" } ] }, { "type": "TextBlock", "weight": "Bolder", "wrap": true, "text": "Top errors" }, { "type": "TextBlock", "wrap": true, "text": "@{if(greater(length(triggerBody()?['topErrors']),0), join(triggerBody()?['topErrors'], decodeUriComponent('%0A')), 'None')}" } ] } ``` ### Step 8 - Post card to Teams Action: **Microsoft Teams - Post card in a chat or channel** Rename: `PostCard` - Post as: `Flow bot` - Post in: `Channel` - Team: your team - Channel: your channel - Card/message body: **Outputs** from `CardJson` ### Step 9 - Capture Teams message ID Action: **Compose** Rename: `MessageId` Expression: ```text @coalesce( body('PostCard')?['id'], body('PostCard')?['messageId'], body('PostCard')?['resourceResponse']?['id'] ) ``` ### Step 10 - Update new SharePoint item with TeamsMessageId Action: **SharePoint - Update item** Rename: `Update_item_2` - Id ```text @body('Create_item')?['ID'] ``` - Title ```text @triggerBody()?['serialNumber'] ``` - DeviceName ```text @triggerBody()?['deviceName'] ``` - Stage ```text @triggerBody()?['stage'] ``` - OverallState ```text @triggerBody()?['overallState'] ``` - LastUpdatedUtc ```text @triggerBody()?['timeUtc'] ``` - TeamsMessageId ```text @outputs('MessageId') ``` --- ## Win32 app install command ```cmd C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Send-AutopilotStatusReport.ps1 -WebhookUrl "PASTE-YOUR-FLOW-URL-HERE" -Secret "hemlig-secret" ``` ## Detection rule Use a file exists rule: ```text C:\ProgramData\AutopilotStatusReporter\installed.tag ```