# Start-Job cmdlet - parsing scriptblock parameter

**URL:** <https://forums.powershell.org/t/start-job-cmdlet-parsing-scriptblock-parameter/880>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/start-job-cmdlet-parsing-scriptblock-parameter/880 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/start-job-cmdlet-parsing-scriptblock-parameter/880/1 "2011-12-31T18:30:00Z")

</div>

by Jim at 2013-04-19 10:42:06

> Why doesn’t this code snippet work?  
>   
> `$cmd = ‘get-process’Start-Job -ScriptBlock {$cmd}`  
>   
> The scriptblock parameter does not expand the variable $cmd. What am I missing? Obviously, I am looking to dynamically build the contents of $cmd at runtime. Otherwise I would just put the literal command within the scriptblock braces.  
>   
> Thanks,  
> Jim

by mjolinor at 2013-04-19 10:46:43

> Try it this way:  
>   
> `$cmd = [scriptblock]::create('get-process')Start-Job -ScriptBlock $cmd`

by ArtB0514 at 2013-04-19 10:57:05

> Since there are numerous ways to accomplish the same task in PowerShell, here’s another:  
> `$cmd = {Get-Process}Start-Job -ScriptBlock $cmd`

by mjolinor at 2013-04-19 11:09:09

> The major difference is that the [scriptblock]::create() method will let you build a script block using an expandable string, and include local variables that will be expanded when the scriptblock is created.

by Jim at 2013-04-19 13:28:26

> Thanks for help!! Good information from both of you. I do like the [scriptblock]::create() technique for the reasons already mentioned.

---

<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, 9:02pm UTC](https://forums.powershell.org/t/start-job-cmdlet-parsing-scriptblock-parameter/880/2 "2024-05-16T21:02:39Z")

</div>

Closed on May 16, 2024, 9:02pm UTC


