PowerShell工作流参考脚本变量

时间:2016-06-20 09:36:51

标签: powershell variables workflow

以下代码可以正常使用Thom

Workflow Test-Fruit {
    foreach -parallel ($I in (0..1)) {
        # Create a custom hashtable for this specific object
        $WORKFLOW:Result = [Ordered]@{
            Name  = $I
            Taste = "Good $I"
            Price = "Cheap $I"
        }

        Parallel {
            Sequence {
                # Add a custom entry to the hashtable
                $WORKFLOW:Result += @{'Color' = "Green $I"}
            }
            Sequence {
                # Add a custom entry to the hashtable
                $WORKFLOW:Result += @{'Fruit' = "Kiwi $I"}
            }
        }

        # Generate a PSCustomObject to work with later on
        [PSCustomObject]$WORKFLOW:Result
    }
}
Test-Fruit

但是当我尝试在父作用域中添加另一个变量时,稍后将在某些Sequence块中使用,这会失败:

Workflow Test-Fruit {
    foreach -parallel ($I in (0..1)) {
        # Create a custom hashtable for this specific object
        $WORKFLOW:Result = [Ordered]@{
            Name  = $I
            Taste = "Good $I"
            Price = "Cheap $I"
        }

        $WORKFLOW:Files = Get-ChildItem -Path c:\

        Parallel {
            Sequence {
                # Add a custom entry to the hashtable
                $WORKFLOW:Result += @{'Color' = "Green $I"}

                if ($I -eq 0) {
                    # Do smething with Files
                    $WORKFLOW:Files.Name | Select-Object -First 1
                }
            }
            Sequence {
                # Add a custom entry to the hashtable
                $WORKFLOW:Result += @{'Fruit' = "Kiwi $I"}

                if ($I -eq 1) {
                    # Do smething with Files
                    $WORKFLOW:Files.Name | Select-Object -Last 1
                }
            }
        }

        # Generate a PSCustomObject to work with later on
        [PSCustomObject]$WORKFLOW:Result
    }
}
Test-Fruit

出现以下错误:

  

项目已添加。键入字典:'颜色'键是   补充:'颜色'项目已添加。词典中的关键词:'水果'   关键词:'水果'

如何定义另一个脚本变量,然后在Sequence块中使用它?

0 个答案:

没有答案