Questions tagged [start-job]

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

205 questions
2
votes
2 answers

Synchronizing PowerShell background jobs

If two background jobs are started from the same session, how can one of them determine that the other has finished? Initially I tried something like this: $j1 = Start-Job { Start-Sleep -Seconds 5 "j1 done" } $j2 = Start-Job { …
Serguei
  • 2,910
  • 3
  • 24
  • 34
2
votes
1 answer

How to use the same powershell function in the main code and a background process

I want to use the same function in a background process that I use in the body of my main code. If I write it this way, the "add" function works for the background process but I cannot use it in the main code. $add = { function add($a,$b) { return…
1
vote
1 answer

Question on use of Powershell start-job -scriptblock or sajb

I see many examples along the lines of: Get-ChildItem -Filter "*.txt" | ForEach-Object { sajb {ren $_.fullname ($_.directoryname + "\" + "temp_" + $_.name + ".newext") } } or what I think should be equivalent, using start-job…
1
vote
4 answers

Powershell dynamic Start-Job command to execute all powershell scripts in subfolders in parallel

For an important data migration, I would like to execute in parallel multiple scripts in side subfolders : I did not succeed to do this : $folders = Get-ChildItem -Directory foreach($folder in $folders){ $cmd = "powershell…
1
vote
1 answer

Build an array of data in a start-job in powershell and return it

$frontlineusers = Get-MsolGroupMember -GroupObjectID $frontline -All Start-Job { $users = $args[0] $allusers2 = @() $svcaccount = "" $admincred = GetAdminCredentials $svcaccount Connect-msolservice -Credential…
JoshT
  • 23
  • 1
  • 8
1
vote
1 answer

Powershell - Start-ThreadJob Ids Incrementing Very Quickly, Why?

New to Powershell and Stackoverflow. Here's my first Powershell Script that I'm trying to optimize to the best of my abilities. My goal is to have the code run as efficiently as possible. Any help/suggestions on that front would be much…
1
vote
0 answers

Call process, then wait until its end or n second before starting next process

I got my main.ps1 script with a loop calling a sub.ps1. Currently I wait until the end of sub.ps1 to run the next one. I would like to do some parallel processing, only in the case that it takes too long. Some subtleties: I can't edit sub.ps1 and I…
Simon
  • 11
  • 2
1
vote
2 answers

How to Start-Job ForEach IP and associate IP with a name for file

I have a script from here, this is the job : function CaptureWeight { Start-Job -Name WeightLog -ScriptBlock { filter timestamp { $sw.WriteLine("$(Get-Date -Format MM/dd/yyyy_HH:mm:ss) $_") } try { …
user18982890
1
vote
1 answer

How to pass arguments to program when using variable as path

I'm trying to start a program in a Start-job scriptblock using a variable for the path. Here is the line: All the there variables work, whole line works when I use c:\plink in place of the $plink variable. It errors out on the -telnet so is not…
user18982890
1
vote
2 answers

Start function as a background job with start-job

I am trying to start a function with start-job. For some reason, I cannot get it to work, the global variables wont pass. My question would be - how to pass global variables to the function and than to start-job without declaring them inside the…
Rusty cole
  • 90
  • 9
1
vote
1 answer

Powershell start-job with arguments not working

I cannot figure this one out. what should have been simple, became a real pain. The following code works. It just that I need to start it in the background and inside a function. The code: $EvidenceDirectory = "C:\Evidence" …
Rusty cole
  • 90
  • 9
1
vote
1 answer

Powershell startjob import-module call function with arguments

So I am trying to start-job from a module I wrote. Copy-Modules.psm1 function startcopy([string] $ShowToCopy) { if (-not($ShowToCopy)) { return "No name provided. Doing nothing." } } else { return "Name Provided $ShowToCopy" } } in the main…
1
vote
0 answers

Start-Job { } | Receive-Job -Wait -Force returns only partial results of batched Get-AzStorageBlob with MaxCount and ContinuationToken

When we call the following, it returns thousands of results. $storageContainer = New-AzStorageContext -ConnectionString $StorageAccountConnectionString ` | Get-AzStorageContainer -Name $BlobContainerName; $MaxCount = 100; $Token =…
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
1
vote
0 answers

Pester 5 test no longer working with Start-Job

This was working before Pester 5.3.0 but now it seems broken and I do not know why it has stopped working. The idea of this tests is to check to see if counters have been removed, this is part of a larger installation and uninstallation. But the…
M Thompson
  • 25
  • 2
1
vote
0 answers

Powershell Start-Job with command

Trying to run Start-Job with following code but it doesn't seem to be working. Not sure where am I going wrong with my understanding about the syntax: $ScriptBlock_test = { cmd /c "`"$mypath\tools\Parser.exe`" -f $some_file --csv…