Workflow variable restrictions



I wonder if someone can help me as I’m confused with the how the output of the following produces what it does. I presume that this is something to do with scopes.

$a = 42
Sequence {$b=$a;
$workflow:c = $a
“variable a is: [$a]”
“variable b is: [$b]”
“variable c is: [$c]”


When I run the above, this is the result I get:

PS C:> Test1
variable a is: [42]
variable b is: []
variable c is: [42]

Why is b empty?

Many thanks, Darren




In my understanding. yes it its because of scoping.

Hi kvprasoon,

thank you for your response.

Can you talk me through it please as I’m a bit confused.

Many Thanks, Darren

Scopes are not a thing limited to workflows. Scope affects everything. It’s fully documented in the help files and of course all over the web in general.


Controlling the Scope of Variables


Understanding scope of functions in powershell workflow



Anything declared at the top level of the workflow is persisted and is considered “global” to that workflow. You’ve done that with the $workflow: modifier as well. Anything inside an activity is scoped to that activity, such as a Sequence.

Workflows are not PowerShell per se; they run under WWF. So you’re dealing with a whole different set of rules, and they’re not always readily apparent. It’s why I dislike Workflow quite a bit.