Questions tagged [powershell-jobs]

The facility described in about_Jobs, PowerShell background jobs.

YOU WILL NOT BE PAID.

43 questions
10
votes
4 answers

How do I call Start-Job which depends on a function in the same powershell module as the function calling Start-Job?

I'm writing some powershell to talk to the AWS API, in a single module. I have written one function, Get-CloudFormation, which returns the status of a CloudFormation. I've written another function, Delete-CloudFormation, which after firing off a…
Peter Mounce
  • 4,105
  • 3
  • 34
  • 65
8
votes
2 answers

How do I capture .NET trace output from a Powershell job?

I am using a .NET component in Powershell which uses Trace.TraceWarning, Trace.TraceInformation etc. I want to output these traces to the console when I run my Powershell script. This works when I use the component in the current session. For…
Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113
7
votes
4 answers

Processing large arrays in PowerShell

I am having a difficult time understanding the most efficient to process large datasets/arrays in PowerShell. I have arrays that have several million items that I need to process and group. This list is always different in size meaning it could be…
BDubs
  • 73
  • 1
  • 14
5
votes
2 answers

How can I tell what processes are started by a Start-Job command?

I have (inherited) a PowerShell script that calls other PowerShell scripts by invoking them with a Start-Job cmdlet and the -FilePath parameter. For example, I have a script that does nothing: Start-Sleep -Seconds 86400 Which I can invoke via a…
Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46
4
votes
0 answers

How to import modules in background in powershell?

I have a few modules in my powershell profile, and their loading sometimes takes a lot of time (10-15s). I would like to load them in a background thread using something like this: Start-Job -ScriptBlock { Import-Module -Global DockerCompletion…
4
votes
1 answer

$Using:var in Start-Job within Invoke-Command

I am using Invoke-Command, and within the -ScriptBlock I am using Start-Job. I have to use $Using:var within Start-Job but the session is looking for the declared variables in the local session (declared before Invoke-Command). Here's a very brief…
Dusty Vargas
  • 863
  • 6
  • 17
4
votes
3 answers

How to pass variable by reference to Powershell job or runspace?

I have Powershell job. $cmd = { param($a, $b) $a++ $b++ } $a = 1 $b = 2 Start-Job -ScriptBlock $cmd -ArgumentList $a, $b How to pass $a and $b by a reference so when the job is done they will be updated? Alternatively how to pass variables…
Yoda
  • 17,363
  • 67
  • 204
  • 344
4
votes
0 answers

Can't use Alternate Credentials to Run Start-Job jobs on Jenkins with PowerShell Plugin

System: Windows Server 2012 R2 | PowerShell v4 | Jenkins v1.607 | 64-Bit Java Version 8u60 For whatever reason, I am able to login to the Windows server that Jenkins is running on, and execute the following code without issues: Start-Job -Credential…
4
votes
2 answers

Can Powershell Receive-Job return a DataSet?

Background Info: I have an application that makes several SQL connections to multiple databases which currently takes a very very long time to execute. Powershell (.NET) will wait for each proceeding "SQL-GET" function to finish before it can fire…
Mitch
  • 43
  • 1
  • 6
3
votes
0 answers

How can a PowerShell job wait on a Job from the parent session?

In order to do some work when another job completes without blocking the current session, I want to create a job that waits on another, however when create the second job, it cannot detect the first job. $Job = Start-Job -ScriptBlock { Start-Sleep…
C. Ross
  • 31,137
  • 42
  • 147
  • 238
3
votes
1 answer

Update a WPF GUI using Powershell Jobs

I've been trying to create responsive GUIs for my personal Powershell scripts. I've come up with a problem that is highly discussed online: Freezing GUI (since Powershell is single threaded). Similar to this problem, but my case is specific to…
scharette
  • 9,437
  • 8
  • 33
  • 67
2
votes
1 answer

How to insert user inputs in powershell jobs?

I have a PowerShell script which starts a background job (it does port-forwarding using kubectl): $forwardjob = Start-Job -ScriptBlock{kubectl port-forward service/db 7125:7125} -Name "Database Port-Forwarder" This works fine, however every so…
Roland Deschain
  • 2,211
  • 19
  • 50
2
votes
1 answer

EventNames of PowerShell jobs started with Start-Job

I want to run a script when a PowerShell job has successfully completed. But how do I find out all possible events of the job started with the Start-Job cmdlet? Here is an example: $myjob = Start-Job { Get-ChildItem } $jobEvent =…
bahrep
  • 29,961
  • 12
  • 103
  • 150
2
votes
1 answer

PowerShell - matching a regex against threadjob output works but doesn't populate $matches variable

When I run the following script from a newly opened PowerShell console, the loop exits so there is clearly a match, but the $matches variable (and thus $matches.PORT) is not populated the first time around. When the script is run again, it is…
R160K
  • 283
  • 2
  • 10
2
votes
1 answer

Modifying PowerShell $using scope variables in thread started with Start-ThreadJob

If I understand the PowerShell Scopes documentation, it should be possible to assign to $using scope variables from threads started using Start-ThreadJob. The documentation says (emphasis mine): The Using scope modifier is supported in the…
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
1
2 3