Questions tagged [start-job]

Start-Job is a Powershell CmdLet to run a Scriptblock as background job

205 questions
82
votes
7 answers

Invoke a second script with arguments from a script

I have a script that reads a configuration file that results in a set of name value pairs that I would like to pass as arguments to a function in a second PowerShell script. I do not know what parameters will be placed in this configuration file at…
39
votes
3 answers

Powershell pass variable to start-job

within powershell I'd like to learn the best way to call a variable to a start job so I don't have to edit the script for each server as it will be specific based on the client I've placed my script on. $Servername = 'Server1' $pingblock = { …
jjamesjohnson
  • 639
  • 1
  • 7
  • 11
34
votes
6 answers

PowerShell Start-Job Working Directory

Is there a way to specify a working directory to the Start-Job command? Use-case: I'm in a directory, and I want to open a file using Emacs for editing. If I do this directly, it will block PowerShell until I close Emacs. But using Start-Job…
jdmichal
  • 10,984
  • 4
  • 43
  • 42
19
votes
4 answers

Powershell - how to pre-evaluate variables in a scriptblock for Start-Job

I want to use background jobs in Powershell. How to make variables evaluated at the moment of ScriptBlock definition? $v1 = "123" $v2 = "asdf" $sb = { Write-Host "Values are: $v1, $v2" } $job = Start-Job -ScriptBlock $sb $job | Wait-Job |…
Ivan
  • 9,089
  • 4
  • 61
  • 74
18
votes
5 answers

Powershell: Run multiple jobs in parralel and view streaming results from background jobs

Overview Looking to call a Powershell script that takes in an argument, runs each job in the background, and shows me the verbose output. Problem I am running into The script appears to run, but I want to verify this for sure by streaming the…
11
votes
3 answers

How to call a powershell function within the script from Start-Job?

I saw this question and this question but couldn't find solution to my problem. So here is the situation: I have two functions DoWork and DisplayMessage in a script (.ps1) file. Here is the code: ### START OF SCRIPT ### function DoWork { $event =…
digitguy
  • 1,014
  • 2
  • 12
  • 29
10
votes
4 answers

Managing the running time of background jobs. Timing out if not completed after x seconds,

I would like to time my background jobs (started with start-job) and time them out after x seconds. I find it hard however to keep track of the running time on each separate job (I am running aprox 400 jobs). I wish there was a way to time out the…
Sune
  • 3,080
  • 16
  • 53
  • 64
10
votes
2 answers

Can I set PowerShell 'Start-Job' with low priority?

I would like to lower the priority of the jobs that I start with Start-Job in PowerShell scripts. Is this possible?
Barry Chum
  • 829
  • 3
  • 14
  • 23
9
votes
3 answers

How can I call many URLs from a list asynchronously

I have a few hundred thousand URLs that I need to call. These are calls to an application server which will process them and write a status code to a table. I do not need to wait for a response (success/fail), only that the server got the request. I…
trueimage
  • 309
  • 2
  • 4
  • 14
8
votes
1 answer

"Start-Process -NoNewWindow" within a Start-Job?

I'm having issues using Start-Process within a Start-Job, specifically when using -NoNewWindow. For example, this test code: Start-Job -scriptblock { Start-Process cmd -NoNewWindow -Wait -ArgumentList '/c', 'echo' | out-null Start-Process…
Joe
  • 3,827
  • 1
  • 25
  • 37
7
votes
2 answers

Background Job in Powershell

I'm trying to run a job in a background which is a .exe with parameters and the destination has spaces. For example: $exec = "C:\Program Files\foo.exe" and I want to run this with parameters: foo.exe /param1 /param2, etc. I know that Start-Job…
Brian
  • 199
  • 4
  • 9
7
votes
1 answer

PowerShell: How 'Receive-Job' pulls output from the job's code block in detail?

Please have a look at this test script and the conclusions I've made about how 'Receive-Job' works in detail. I have still issues to figure out, how exaclty 'Receive-Job' pulls the streams from the code block. <# .SYNOPSIS Test the console output…
andiDo
  • 309
  • 4
  • 11
7
votes
1 answer

Powershell Start-job synchronous output

I have a powershell script that starts a job start-job -scriptblock { while($true) { echo "Running" Start-Sleep 2 } } and then it continues executing the rest of the script. That job, is kind of a monitoring one for the PID of that…
nikkatsa
  • 1,751
  • 4
  • 26
  • 43
7
votes
2 answers

Start-job vs. Invoke-command -asjob

I'm trying to do basic background jobs in PowerShell 2.0, and I'm seeing different things with start-job and invoke-command -asjob. If I do this: start-job -scriptblock {get-process} I get a job object, but the child job (which is created…
Mike Shepard
  • 17,466
  • 6
  • 51
  • 69
6
votes
4 answers

PSExec never completes when run inside start-job

I'm trying to execute a cmd file on a list of 48 computers. I don't want to execute and wait for completion sequentially because each cmd takes about 10 minutes to complete. WinRM isn't an option. Neither is WMI. PSExec is an option....but I…
Rob Wiley
  • 85
  • 1
  • 7
1
2 3
13 14