# Workflow variable restrictions

**URL:** <https://forums.powershell.org/t/workflow-variable-restrictions/11462>\
**Category:** PowerShell Help\
**Created:** [October 11, 2018, 11:23am UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462 "2018-10-11T11:23:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 11, 2018, 11:23am UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/1 "2018-10-11T11:23:14Z")

</div>

Hello,

&nbsp;

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.

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

&nbsp;

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

PS C:&gt; Test1  
variable a is: [42]  
variable b is:   
variable c is: [42]

Why is b empty?

Many thanks, Darren

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [October 11, 2018, 11:57am UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/2 "2018-10-11T11:57:34Z")

</div>

In my understanding. yes it its because of scoping.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [October 11, 2018, 12:52pm UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/3 "2018-10-11T12:52:45Z")

</div>

Hi kvprasoon,

thank you for your response.

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

Many Thanks, Darren

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [October 11, 2018, 6:16pm UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/4 "2018-10-11T18:16:24Z")

</div>

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.

about\_Scopes

> https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about\_scopes?view=powershell-6

&nbsp;

Controlling the Scope of Variables

> https://blogs.msdn.microsoft.com/powershell/2007/04/14/controlling-the-scope-of-variables
> 
> &nbsp;

  
Understanding scope of functions in powershell workflow

> https://social.technet.microsoft.com/Forums/office/en-US/6a0b36e6-6fc6-4c46-9792-5d088213ef19/understanding-scope-of-functions-in-powershell-workflow

WorkFlow

> https://docs.microsoft.com/en-us/powershell/module/psworkflow/about/about\_workflows
> 
> > **[Windows PowerShell Workflow Concepts](https://learn.microsoft.com/en-us/system-center/sma/overview-powershell-workflows?view=sc-sma-1807)**
> >
> > Provides a brief overview of critical features of workflows that are common to Automation runbooks.
> 
> > **[PowerShell Workflows: The Basics - Scripting Blog \[archived\]](https://devblogs.microsoft.com/scripting/powershell-workflows-the-basics/)**
> >
> > Summary: Windows PowerShell MVP Richard Siddaway talks about the basics of Windows PowerShell 3.0 workflows. Microsoft Scripting Guy, Ed Wilson, is here. Today, we are fortunate to have a guest blog post by Windows PowerShell MVP Richard...
> 
> [PowerShell Workflows: Nesting - Scripting Blog [archived]](https://blogs.technet.microsoft.com/heyscriptingguy/2013/01/09/powershell-workflows-nesting)

  
&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [October 12, 2018, 9:46am UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/5 "2018-10-12T09:46:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/workflow-variable-restrictions/11462/6 "2024-05-16T20:34:16Z")

</div>

Closed on May 16, 2024, 8:34pm UTC


