Questions tagged [start-job]

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

205 questions
1
vote
1 answer

Powershell start-job scope

I have a long script. i have a function for logging: function Log ([string]$Content){ $Date = Get-Date Add-Content -Path $LogPath -Value ("$Date : $Content") } In some point at the script i have the need to run jobs in parallel. I have a…
Shahar
  • 461
  • 5
  • 16
1
vote
0 answers

Powershell Start-Job and Start-ThreadJob performance

I need to run a function more than 200 times simultaneously with PowerShell. So far I have two options Start-Job and Start-ThreadJob. In both cases I use a "launcher" as is $MyFunction = [scriptblock]::Create(@" Function FunctionName…
Yann Greder
  • 71
  • 1
  • 6
1
vote
1 answer

Powershell Cannot convert value of type "System.String" to type "System.Management.Automation.ScriptBlock"

I am new to this Job things. I am getting the error of : Cannot bind parameter 'ScriptBlock'. Cannot convert the | ".\test7\test7-2.ps1" value of type "System.String" to type "System.Management.Automation.ScriptBlock". Can anyone tell me and figure…
bah
  • 13
  • 1
  • 5
1
vote
2 answers

Powershell | Speed up Running Get-ADUser in Powershell jobs

I'm working on a tool that can quickly run through a csv and search AD for the relevant information provided I have made a gui that will let the user align the header of a CSV with the AD search method My main issue at the moment is when searching…
Luke Hagar
  • 13
  • 3
1
vote
1 answer

Powershell Start-job new window run as administrator

I have script which write some COMMAND to another script and start them in new window with Start-Job command (I really need that). $cred is credential of local administrator. Main script started from powershell windows which opened "run as…
Roman
  • 11
  • 1
  • 2
1
vote
0 answers

Powershell - Need background job to read serial output to TextBox

I'm making a program that connects to a 3D printer, and sends/receives commands from it. I'm trying to figure out how to take the output from $port.ReadLine() and send it to a TextBox (ReadOnly output in my GUI). I have since edited this OP to…
Noah
  • 93
  • 2
  • 9
1
vote
1 answer

Powershell - How to call two functions using Start-Job within a function and pass a list of computer names?

I have a main script that imports a module \path\to\functions.psm1, I call a function in the main script named: Run_Scans $ServerList, which is from functions.psm1, From Run_Scans I try and call two other functions (Scan1,Scan2) using Start-Job, but…
Chris
  • 17
  • 5
1
vote
4 answers

Run docker in background under Powershell

Simple question, I want to run docker command in background. (Actually running any command with command line parameters under Powershell is my real question, but docker is a simple concrete one) I have a command docker run -ti --rm -e…
xpt
  • 20,363
  • 37
  • 127
  • 216
1
vote
1 answer

Why do I get different output in Powershell from start-job vs just running the code?

The script runs correctly when outside of Start-Job but when in a scriptblock I get incorrect results. Where am I going wrong? I need the Start-Job functionality since I have servers where the remote commands will hang (separate problem - WMI is…
Luke Fowler
  • 83
  • 2
  • 8
1
vote
3 answers

Start-Job only runs if I wait for completion

I have a Start-Job -ScriptBlock that will run correctly if I wait for the job to complete. If I don't wait/receive job completion status, the -ScriptBlock does not run. I'm not sure what I'm missing. Likely not understanding fundamental behaviour of…
Joey
  • 59
  • 4
1
vote
0 answers

Background jobs stops after a few minutes

See below a simplified version of my PowerShell code. $cred = Import-Clixml d:\cred.xml Invoke-Command -ComputerName $computer -Authentication Credssp -Credential $cred -InDisconnectedSession -SessionOption…
JET
  • 11
  • 1
1
vote
0 answers

How can I make powershell job to return the object type I want?

I'm trying to use powershell job in order to build a TreeView object and return it, instead, I get PSObject type everytime the job ends. I've tried returning the TreeView object in many ways, like adding [System.Windows.Forms.TreeView] before the…
EnTm
  • 163
  • 1
  • 1
  • 6
1
vote
2 answers

How to use a text file as input for a scriptblock - working directory in background jobs

I have been given the task to write a PS script that will, from a list of machines in a text file: Output the IP address of the machine Get the version of the SCCM client on the machine Produce a GPResult HTMl file OR Indicate that the machine is…
DavidM
  • 23
  • 3
1
vote
0 answers

Powershell: Copy-Item from within Start-Job seems to work, but file is missing afterwards

I created the following script block, which should look for a file matching a regex on a UNC path and copy it to the target folder: $ScriptBlock = { param ( [string]$serverName, [string]$ip, [string]$fullPathRegEx, …
user2727133
  • 149
  • 1
  • 12
1
vote
1 answer

Selenium in powershell does not work with Start-Job command

I have the following .dll files in order to run selenium through powershell: You can ignore the extension files. Basically what I want to have happen is to use the Start-Job command in order to open two chrome browsers at the same time, and go to…
K Split X
  • 3,405
  • 7
  • 24
  • 49