【问题标题】:Powershell Workflow DynamicActivity Compiler Error '.' Expected Using $Date VariablePowershell 工作流 DynamicActivity 编译器错误“。”预期使用 $Date 变量
【发布时间】:2015-01-23 16:11:47
【问题描述】:

通常,powershell 错误会给我一些东西,但这个错误让我陷入了一个循环。要测试,请执行以下代码:

workflow test-date{
    $Date = Get-Date -format yyyyMMddHHmm -Verbose

    Write-Output $Date
}

我得到的错误是:

The workflow 'test-date' could not be started: The following errors were encountered while processing the workflow tree:
'DynamicActivity': The private implementation of activity '1: DynamicActivity' has the following validation error:   Compiler error(s) encountered processing expression "Date".
'.' expected.
At line:383 char:21
+                     throw (New-Object System.Management.Automation.ErrorRecord $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (System.Manageme...etersDictionary:PSBoundParametersDictionary) [], RuntimeException
    + FullyQualifiedErrorId : StartWorkflow.InvalidArgument

真正让我着迷的是它说它期待一个“。”某处。我不知道它会在哪里找到一个'.'。我用谷歌搜索了与我的情况没有任何关系的错误。我想更多地了解这个错误意味着什么,以及为什么我得到它。如果有人也知道解决方案,那就太好了。

【问题讨论】:

    标签: powershell compiler-errors workflow-foundation


    【解决方案1】:

    我不知道实际原因,但是如果您将变量 $date 重命名为 $something_else,则工作流可以正常工作。

    如:

    Workflow Test-Date {
        $aDate = Get-Date Get-Date -format yyyyMMddHHmm
        $New_Date = Get-Date -format yyyyMMddHHmm
    
        Write-Output $aDate
        Write-Output $New_Date
    }
    

    我假设它在转换过程中触发了 .NET 中的关键字。

    【讨论】:

      【解决方案2】:

      发件人:http://blogs.msdn.com/b/powershell/archive/2012/07/21/new-workflow-makeiteasy-authoring-workflows-using-powershell-extended-syntax.aspx

      默认情况下,工作流中的每个命令都在不共享 PowerShell 状态的情况下执行

      不知道错误与此有何关联,但这肯定是个问题,因为

      一个命令创建的变量对下一个命令不可见。

      所以你应该做的是使用inlinescript

      workflow test-date{
          inlinescript{
              $Date = Get-Date -format "yyyyMMddHHmm" -Verbose
              Write-Output $Date
          }
      }
      

      输出:

      PS C:\Users\mcameron> test-date
      201501231144
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-29
        • 1970-01-01
        • 2022-09-29
        • 2021-03-06
        • 1970-01-01
        相关资源
        最近更新 更多