首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mule PowerShell连接器-变量$<变量名称>无法检索,因为它没有被设置

Mule PowerShell连接器-变量$<变量名称>无法检索,因为它没有被设置
EN

Stack Overflow用户
提问于 2018-07-18 20:31:06
回答 1查看 5.7K关注 0票数 4

无法理解为什么我的PowerShell脚本中的变量总是说变量为null (错误:变量'$‘由于未设置而无法检索。)

Mule Flow = HTTP -> Set有效载荷-> PowerShell -> Logger -> End

~ MULE代码片段-使用PowerShell连接器3.x版本

代码语言:javascript
复制
<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码~

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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脚本的参数值的传递。删除代码行后,参数将使用值进行设置。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51410527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档