This post will elaborate on the cmdlet “Start-Job” in PowerShell.
What is the “Start-Job” Cmdlet in PowerShell?
The “Start-Job” cmdlet starts the job in the background on a local computer’s current session. It returns the job object immediately, despite the fact that the job is taking longer than expected time to finish it. Job objects contain useful information regarding the job.
How Does the “Start-Job” Cmdlet Work?
As it is described above, the “Start-Job” cmdlet is used for starting a job in the background of a local computer. Let’s have a look at practical demonstrations of the given cmdlet.
Example 1: Use the “Start-Job” Cmdlet to Start a Background Job in PowerShell
To start a job in the background, the “Start-Job” cmdlet can be used. Then, add the “-ScriptBlock” parameter and assign it the stated command to start a job:
Example 2: Use the “Start-Job” Cmdlet to Run the Script as a Background Job
To run a script as a background job, first, specify the “Start-Job” cmdlet and then provide the script file path by using the “-Path” parameter:
Example 3: Use the “Start-Job” Cmdlet to Get a Process Using a Background Job
Execute the following command to get a process by using its name:
According to the above-stated command:
- Initially, add the “Start-Job” cmdlet alongside the “-Name” parameter and assign it the process name.
- Next, specify the “-ScriptBlock” parameter and assign it the stated cmdlet to initiate a job:
Example 4: Use the “Start-Job” Cmdlet With the “-ArgumentList” Parameter to Specify an Array
To specify an argument array list, execute the provided command:
Here:
- Use the “Start-Job” cmdlet and the “-ScriptBlock” parameter having the stated cmdlet assigned to it.
- Next, mention the “-ArgumentList” parameter and provide it with two arguments separated by a comma:
That’s all! We have demonstrated PowerShell’s “Start-Job” cmdlet in-depth.
Conclusion
The “Start-Job” cmdlet in PowerShell is used to start a background process on a local computer. Users can continue to work on other tasks while the background job continues to run. This post has explained the “Start-Job” cmdlet in detail with the assistance of several examples.