无法理解为什么我的PowerShell脚本中的变量总是说变量为null (错误:变量'$‘由于未设置而无法检索。)
Mule Flow = HTTP -> Set有效载荷-> PowerShell -> Logger -> End
~ MULE代码片段-使用PowerShell连接器3.x版本
<powershell:execute config-ref="PowerShell" doc:name="PowerShell" scriptFile="classpath:powershell-script.ps1">
<powershell:parameters>
<powershell:parameter key="variable1">#[groovy: payload.variable1 ?: '']</powershell:parameter>
<powershell:parameter key="variable2">#[groovy: payload.variable2 ?: '']</powershell:parameter>
<powershell:parameter key="variable3">#[groovy: payload.variable3 ?: '']</powershell:parameter>
<powershell:parameters>
<powershell:execute>~ PowerShell码~
Set-StrictMode -Version Latest
Param($variable1, $variable2, $variable3)
#Create NEW AD accounts
Function Start-Commands
{
Write-Output "Start-Commands"
Write-Output "Parameters-: $variable1 - $variable2 - $variable3"
}
Start-Commands~控制台输出~
根异常堆栈跟踪: org.mule.modules.powershell.PowershellException:无法发送消息。抛出了一个异常:[{"Exception":"System.Management.Automation.RuntimeException:变量“$flowVarManager”无法检索,因为它尚未设置。\r\n
发布于 2018-07-19 14:40:18
要解决这个问题,我删除了Set-StrictMode -Version最新的
根据我的研究,我发现这篇文章是-> https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-6
Set-StrictMode cmdlet为当前作用域和所有子作用域配置严格模式,并将其打开和关闭。当严格模式打开时,当表达式、脚本或脚本块的内容违反基本的最佳实践编码规则时,Windows PowerShell会产生终止错误。
当Set-StrictMode打开时,它会干扰从MS PowerShell连接器- Mule 3到PS脚本的参数值的传递。删除代码行后,参数将使用值进行设置。
https://stackoverflow.com/questions/51410527
复制相似问题