Questions tagged [powershell-jobs]

The facility described in about_Jobs, PowerShell background jobs.

YOU WILL NOT BE PAID.

43 questions
2
votes
1 answer

PowerShell getting logs from Jobs

I am using a PowerShell module called Logging. I use other Jobs to do some work, but unforunately the logs that I write in them are not received by the command Receive-Job. function Get-Topic { [CmdletBinding(DefaultParameterSetName =…
Garbem
  • 149
  • 1
  • 13
2
votes
3 answers

Write to external array inside a running powershell job

I am trying to write data to external array while running a powershell job- This is my code sample that I' m trying- $datafromJob = @() $wmijobs = @() foreach ($c in $computers) { $wmijobs += Start-Job -Name WMIInventory -ScriptBlock { …
2
votes
2 answers

Can *.ps1 scripts run as background jobs themselves execute *.ps1 scripts?

I want to run 15 instances of a script that pipelines 5 scripts together, and so far I'm missing the pixie dust. I've boiled the problem down to a test case with a master script that calls a slave script that in turn calls a sub_slave script (no…
codepoke
  • 1,272
  • 1
  • 22
  • 40
2
votes
1 answer

new-pssession in scheduled job

I want to write script that enables mail forwarding for some user on exchange server and turn it off at specified time. But when $script_bloc executes in job: New-PSSession returns null without any error. I can pass to New-PSSession hardcoded…
2
votes
2 answers

Is there any way to tell what script is running when started with start-job -filename?

I'm starting a PowerShell job with something like the following command: start-job -filename my_script.ps1 -argumentlist ($v1, $v2, $v3) This script, however needs to know where it's located, because it runs other commands based on their location…
Mark
  • 11,257
  • 11
  • 61
  • 97
2
votes
3 answers

Powershell: passing parameters to functions stored in variables

I'm trying to get a simple working example of using functions inside of jobs. I've managed to pass my function into the scriptblock used for my job, but I can't seem to get parameters to the function. # concurrency $Logx = { param( …
JDH
  • 2,618
  • 5
  • 38
  • 48
1
vote
1 answer

How does Receive-Job keep correct orders of records

I am trying to understand how Receive-Job works internally. In below code I can see where Job object keeps records from different steams: $InformationPreference = 'SilentlyContinue' $sb = { $VerbosePreference = 'Continue' …
Zergatul
  • 1,957
  • 1
  • 18
  • 28
1
vote
2 answers

How do I debug a PowerShell background job?

Jason Archer helped me solve my last issue, but in testing his solution I stumbled across the real problem. My server won't run chained background jobs correctly, but my laptops will. If I run the scripts in the previous problem on my laptops, they…
codepoke
  • 1,272
  • 1
  • 22
  • 40
1
vote
1 answer

Assign a variable inside of a scriptblock while running a job

Related to Terminate part of powershell script and continue. Partially related to Powershell Job Always Shows Complete. My script runs locally and access the registry hive of a remote PC. I need the value of registry keys to be written into a…
1
vote
1 answer

Powershell Speed Up Get-MessageTrackingLog

Currently I am trying to get an output of all disabled users and their message counts in exchange. This is easy enough through a foreach loop: $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri…
1
vote
1 answer

Calling workflow from another workflow as a job in powershell

I have to call a long running workflow from another workflow asynchronously. Is there a way to do that in powershell? workflow CalledWorkflow { Start-Sleep -s 100; } workflow CallingWorkflow { CalledWorkflow "CalledWorkFlow Invoked" } Now…
saravanan
  • 398
  • 4
  • 13
1
vote
1 answer

Powershell Invoke-Command remotely with -AsJob failed to launch remote program

I want to launch a long-running remote program but don't want to wait. So I put below one line command in PS script file and run "Powershell -file xxx.ps1" Invoke-command server1 {xxx.exe} -AsJob But the remote program is not running after the…
Sheen
  • 3,333
  • 5
  • 26
  • 46
1
vote
2 answers

Powershell: Exception calling "GetOwner" : "Not found " when invoked as job

I need to get some procs by the owner. My demo script below will first look for procs by owner locally, then it will do the same thing, but it invokes the command on the same box: cls write-host 'LOCAL CALL: ' $procs = @(Get-WmiObject win32_process…
JDH
  • 2,618
  • 5
  • 38
  • 48
1
vote
1 answer

no receive-job results for gci when -path is a variable

This returns nothing: $x = "C:\temp" Start-Job -ScriptBlock {get-childItem -path $x} | Wait-Job | Receive-job But providing the path parameter without a variable, like so... Start-Job -ScriptBlock {get-childItem -path C:\temp} | Wait-Job |…
noam
  • 1,914
  • 2
  • 20
  • 26
1
vote
1 answer

Powershell: Unexpected results in Receive-Job

I'm trying to get a better understanding of how powershell handles jobs. Both of these article posts helped a lot: Multi-Threading in powershell Pass array to Start-Job However, with the following sample script, I am getting unexpected results…