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

Azure Automation中Logic Apps传参至PowerShell脚本失败求助

解决Azure Automation PowerShell作业参数转换失败问题

你的报错核心原因是Logic Apps传递的是JSON对象而非字符串,但脚本参数定义为[string],类型不匹配导致参数转换失败。以下是两种可行的修复方案:

方案一:修改PowerShell脚本适配JSON对象

直接将参数类型从[string]改为[PSObject],跳过字符串转JSON的步骤,直接处理结构化对象:

param (
 [Parameter(Mandatory=$true)]
 [PSObject]$azureArcJson,
 [Parameter(Mandatory=$true)]
 [PSObject]$crowdstrikeJson
 )
 
try {
 # 调试输出对象数量
 Write-Output "Azure Arc对象数量: $($azureArcJson.Count)"
 Write-Output "Crowdstrike对象数量: $($crowdstrikeJson.Count)"
 
 # 直接从对象提取主机名
 $azureArcHostnames = $azureArcJson | ForEach-Object { $_.Hostname }
 $crowdstrikeHostnames = $crowdstrikeJson | ForEach-Object { $_.Hostname }
 
 # 对比差异
 $azureArcMissing = $crowdstrikeHostnames | Where-Object { $_ -notin $azureArcHostnames }
 $crowdstrikeMissing = $azureArcHostnames | Where-Object { $_ -notin $crowdstrikeHostnames }
 
 # 格式化输出结果
 $output = "Azure Arc与Crowdstrike主机名差异:`n"
 $output += "仅存在于Crowdstrike的主机名:`n"
 $output += ($azureArcMissing -join "`n")
 $output += "`n`n仅存在于Azure Arc的主机名:`n"
 $output += ($crowdstrikeMissing -join "`n")
 
 Write-Output $output
 }
 catch {
 Write-Error "错误详情: $_"
 }

方案二:在Logic Apps中转换参数为字符串

如果不想修改脚本,在Logic Apps调用Azure Automation作业的步骤中,将输入参数的值用string()函数包裹,强制转换为JSON字符串:

  • 例如,将azureArcJson的参数值设置为string(triggerBody()['azureArcData'])(替换为你实际的JSON对象路径)
  • 确保传递给脚本的是JSON格式的字符串,而非结构化对象

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 05:32:32