# How do I use workflows in cmdlets?

**URL:** <https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479>\
**Category:** PowerShell Help\
**Created:** [April 21, 2014, 2:44am UTC](https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479 "2014-04-21T02:44:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregory-suvalian](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@gregory-suvalian](https://forums.powershell.org/u/gregory-suvalian)\
**Post date:** [April 21, 2014, 2:44am UTC](https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479/1 "2014-04-21T02:44:43Z")

</div>

hello,

I have written cmdlet which cleans up space on remote servers via WMI calls. It works fine but it obviously runs in sequence if I have to do multiple servers. My understanding I need to implement this as workflow to run in parrallel. I wrapped my entire cmdlet in workflow CleanUpSpace{} and I assumed I can just call CleanUpSpace -computers “COMP1”, COMP2" from withing cmdlet but it would not work complaining that CleanUpSpace is not recognized as cmdlet. What am I doing wrong. Code is below

```
$hf_mig
```

---

<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:** [April 21, 2014, 3:06am UTC](https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479/2 "2014-04-21T03:06:37Z")

</div>

No, you don’t need to write it as a workflow just to have in run in parallel. That’s one option, but just one. Workflows are a lot more complex.

Workflows work best when you’ve enabled Remoting on your target computers - workflow’s main intent is to push the workflow out to the targets, and have the script actually run locally on each target.

But workflows aren’t PowerShell scripts. They’re run in WWF - and as you’ve seen, it doesn’t work quite the same as PowerShell. You’d likely have to do an InlineScript() element that defines and runs your function. That can, in turn, be parallelized.

---

<div class="post-metadata">

**Author:** ![gregory-suvalian](https://avatars.discourse-cdn.com/v4/letter/g/9d8465/32.png) [@gregory-suvalian](https://forums.powershell.org/u/gregory-suvalian)\
**Post date:** [April 21, 2014, 3:27am UTC](https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479/3 "2014-04-21T03:27:17Z")

</div>

Remoting is not an option for us, so I have to run everything through WMI.  
So how do I do what I need to do in parrallel, then? Foreach -parallel requiring workflow

---

<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:52pm UTC](https://forums.powershell.org/t/how-do-i-use-workflows-in-cmdlets/2479/4 "2024-05-16T20:52:08Z")

</div>

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


