Powershell工作流DynamicActivity编译器错误'.' 预期使用$ Date变量

Col*_*337 4 powershell compiler-errors workflow-foundation

通常,PowerShell错误会给我一些东西,但是这个错误让我经历了一个循环.要测试,请执行以下代码:

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

    Write-Output $Date
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

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
Run Code Online (Sandbox Code Playgroud)

真正让我感到高兴的是,它说它期待着"." 某处.我不知道它在哪里找到'.'.我用谷歌搜索了没有产生任何与我的情况相关的错误.我想更多地了解这个错误的含义,以及为什么我会得到它.如果有人知道解决方案,那就太好了.

gre*_*fly 5

我不知道实际原因,但如果将变量重命名$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
}
Run Code Online (Sandbox Code Playgroud)

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