@John-305 的答案是正确的。你的陈述有括号问题。正确的说法是:
“@contains(tolower(items('For_each')['VM']), 'myvm1')”
试试这个逻辑应用以供参考:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Condition": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "result",
"value": "@items('For_each')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"expression": "@contains(tolower(items('For_each')['VM']), 'myvm1')",
"runAfter": {},
"type": "If"
}
},
"foreach": "@body('Parse_JSON')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "result",
"type": "Array"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": [
{
"PSComputerName": "localhost",
"PSShowComputerName": true,
"PSSourceJobInstanceId": "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3",
"Success": true,
"VM": "MyVM1"
},
{
"PSComputerName": "localhost",
"PSShowComputerName": true,
"PSSourceJobInstanceId": "5e18cd92-5676-4ed6-a7e4-14b0d9fea3b3",
"Success": true,
"VM": "MyVM2"
}
],
"schema": {
"items": {
"properties": {
"PSComputerName": {
"type": "string"
},
"PSShowComputerName": {
"type": "boolean"
},
"PSSourceJobInstanceId": {
"type": "string"
},
"Success": {
"type": "boolean"
},
"VM": {
"type": "string"
}
},
"required": [
"VM",
"Success",
"PSComputerName",
"PSShowComputerName",
"PSSourceJobInstanceId"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {},
"type": "ParseJson"
},
"Response": {
"inputs": {
"body": "@variables('result')",
"statusCode": 200
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Response"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}