DARKOCEAN
DARKOCEAN

Reputation: 109

Powershell Start-Job not behaving correctly

I have several PHP scripts, which execute a Powershell Script to obtain performance counters of my server infrastructure. As I have multiple scripts, I wanted to execute them all at the same time, from just one location.

I have created the following Start-Job script, which when run in the ISE, works perfectly fine.

Start-Job Script

When I run the ps1 script itself, using the below command, I get a list of the jobs that have started, but nothing actually happens. It just doesn't do anything, but also gives me zero errors.

Executing PS1 file

So, what am I missing?

Upvotes: 1

Views: 1457

Answers (1)

Mark Wragg
Mark Wragg

Reputation: 23355

Per the comments, when the calling powershell session terminates it is terminating all of the background jobs it started.

To make it wait for the jobs to complete before terminating add Get-Job | Wait-Job at the end of your script.

Upvotes: 4

Related Questions