Questions tagged [start-job]

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

205 questions
5
votes
1 answer

Jenkins won't run Start-Job with Credential parameter

I pass in credentials to the script via the env injector (note this works for me with Invoke-Command) and try to run Start-Job but jenkins doesn't like it: $user = $ENV:user $pass = $ENV:pass write-output (cat env:username) write-output (cat…
red888
  • 27,709
  • 55
  • 204
  • 392
4
votes
1 answer

Why can't a thread created by PowerShell execute script functions?

I have a script function that calls. net to manipulate word documents. It works. Now I want to create a sub-thread to execute it, and then the main thread decides whether it completes or exceeds the specified time, and ends it after that time. …
4
votes
5 answers

Cannot bind parameter to argument 'command' because it is null. Powershell

I had a function similar to below code. It receives command and the command arguments. I had to run this command in background and collect the output. But that last statement is bugging me with this error Error: Cannot bind argument to parameter…
srikanth peetha
  • 229
  • 1
  • 3
  • 17
4
votes
1 answer

-s when using Start-Job in powershell

I am trying to call a Start-Job in powershell. When I do, it spawns a background powershell with the following arguments: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 5.0 -s -NoLogo -NoProfile -EncodedCommand [encoded command I…
Ghi102
  • 153
  • 9
4
votes
1 answer

Powershell Job "Completed" but did not finish it's task

I am trying to start/stop services via a job in powershell. In testing this on my local machine, the job will go to a completed state but the service will not change its status. Is there a way to get a better view of what my job did? Here is the…
Christopher
  • 790
  • 12
  • 30
4
votes
1 answer

PowerShell: Start-Job -scriptblock Multi line scriptblocks?

Hoping someone can help me to figure out if this is possible. I have a 20 ish lines that scan a log file in a while loop. I need this to happen in parallel with the rest of the script. The log scanning loop is passing the entries into SQLite and…
SynxUK
  • 83
  • 1
  • 10
4
votes
1 answer

Start-Job including custom cmdlet terminates with strange error

I developed some custom cmdlets that serve for different importing tasks to a SharePoint system. Currently all those cmdlets are being run in a serial kind in a single PowerShell script. I want to change this so that each cmdlet gets executed in a…
4
votes
2 answers

Use hashtable as parameter when splatting?

I am trying to use Start-Job to launch a new Powershell script. The new script has several parameters (some optional, some not), so I want to make a hashtable and splat them. However, one of these parameters is itself a hash table. I am trying to…
DataBeast
  • 75
  • 1
  • 7
4
votes
4 answers

Using powershell object to execute scripts

Powershell version used: 3.0 Hello everyone, I'm looking to try and create a new Powershell pipeline and execute a script within it, then get the output it produces into an output variable, but I can't get any output produced from within the object…
cloud_hero
  • 163
  • 1
  • 7
3
votes
1 answer

Resubmit hanging job (start-job)

I am starting several jobs (with Start-Job) and at the end of my script i do a check to see if the jobs have been running more than X seconds. I would then like to take the Running and Failed jobs and restart them until they succeed. The jobs are…
Sune
  • 3,080
  • 16
  • 53
  • 64
3
votes
1 answer

Reuse 2 functions in Start-ThreadJob

Assuming Get-Foo and Get-Foo2 and Deploy-Jobs are 3 functions that are part of a very large module. I would like to use Get-Foo and Get-Foo2 in Deploy-Jobs's Start-ThreadJob (below) without reloading the entire module each time. Is an working…
MKANET
  • 573
  • 6
  • 27
  • 51
3
votes
1 answer

Cannot start job with foreach-object in parallel

I have prepared this script to try to execute in parallel the same function multiple times with different parameters: $myparams = "A", "B","C", "D" $doPlan = { Param([string] $myparam) echo "print $myparam" # MakeARestCall is a…
Manu
  • 4,019
  • 8
  • 50
  • 94
3
votes
2 answers

How can I put a timeout on a powershell command?

I tried this code but only file1.txt gets created. File2.txt does not. I'm looking for the built-in way to use timeouts. So not by creating custom loops. Out-File "file1.txt" #this file is created $Job = Start-Job -ScriptBlock { …
Ferro
  • 1,863
  • 2
  • 14
  • 20
3
votes
1 answer

Start-Job scriptblock passing of variable

I got a PowerShell script that starts another script and passes parameters to it. I do this with Start-Job as I do not want to wait until the second script is finished: ScriptA: start-job -name EnableAutoUnlock -scriptblock {Invoke-Command -script…
architekt
  • 147
  • 11
3
votes
1 answer

Powershell Start-Job won't run

I'm trying to run a simple job process in powershell 2.0 and it doesn't seem to run. $job = Start-Job { Return "Some string." } When I call $job, the status says it's running. But the problem is that it never completes. Tried the same thing on…
foureight84
  • 402
  • 2
  • 7
  • 19
1
2
3
13 14