将PowerShell脚本转换为Logic Apps(第二部分):数据处理实现咨询
Since you’ve already handled the login/logout flows in Logic Apps, let’s focus on replicating the core data filtering, selection, export, and formatting steps from your PowerShell script. Here’s a step-by-step breakdown of how to map each operation to Logic Apps actions:
Prerequisite
First, ensure you have an HTTP action that retrieves the Grid data (equivalent to your Invoke-RestMethod call to SPDEDMHAPI.GRIDGET). Let’s assume this action is named Get_Grid_Data—we’ll reference its output throughout these steps.
Step 1: Filter Rows Where PR_OWN Equals "SC-CO-001"
This replaces your PowerShell where {$_.PR_OWN -eq "SC-CO-001"} line:
- Add a Filter Array action (under the Data Operations group).
- From: Select the
Payloadarray from your HTTP response:body('Get_Grid_Data')?['Payload'] - Condition: Click "Add condition", then set:
- Left operand:
item()?['PR_OWN'] - Operator:
is equal to - Right operand:
"SC-CO-001"
- Left operand:
- From: Select the
Step 2: Select Specific Properties
This replicates Select-Object -Property PR_SNAM, PR_OWN, PR_NAME, PR_ADD4, PR_TENR, PR_USER1:
- Add a Select action (under Data Operations).
- From: Choose the output of the Filter Array action:
body('Filter_Array') - Map: For each property you need, define a key-value pair:
PR_SNAM:item()?['PR_SNAM']PR_OWN:item()?['PR_OWN']PR_NAME:item()?['PR_NAME']PR_ADD4:item()?['PR_ADD4']PR_TENR:item()?['PR_TENR']PR_USER1:item()?['PR_USER1']
- From: Choose the output of the Filter Array action:
Step 3: Export to XML File
Logic Apps doesn’t have a direct equivalent to PowerShell’s Export-Clixml (which uses a proprietary serialization format), but you can generate standard XML and save it to a file:
- Convert to XML: Add a Convert to XML action (Data Operations).
- Content: Select the output of the Select action:
body('Select') - Root name: Optional (e.g.,
"Properties"to add a valid root element to your XML)
- Content: Select the output of the Select action:
- Save to File: Add a Create File action (use the File System connector with an on-premises gateway for local paths like
C:\Test\API\, or Azure File Storage for cloud storage):- File path:
Test/API/XML_Sample.xml - File content: Select the output of the Convert to XML action:
body('Convert_to_XML')
- File path:
Step 4: Format Data as a Table
To replicate Format-Table -AutoSize for logging or visibility:
- Add a Create HTML Table action (Data Operations).
- From: Select the output of the Select action:
body('Select')
- From: Select the output of the Select action:
- You can then use this HTML table in downstream actions:
- Log it to Azure Monitor with a Log to Azure Monitor action
- Send it via email using Send Email (V2)
- Display it in a notification
Notes
- If you strictly need the exact
Clixmlformat (rare for non-PowerShell use cases), you can wrap theExport-Clixmlcommand in an Azure Function (using the PowerShell runtime) and call it from Logic Apps. - Always test each action individually to verify the output matches your expected results.
内容的提问来源于stack exchange,提问作者AlHal

