Questions tagged [start-job]

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

205 questions
2
votes
1 answer

Remote Get-WmiObject call fails when within Start-Job scriptblock

Alright, I've tried to figure this out, but figured it's time to ask the interwebs. I'm wondering if this is a bug or what. I'm trying to start jobs against multiple computers to determine which database names reside on them. My Computer1 system…
Tom
  • 21
  • 1
  • 3
2
votes
2 answers

Why are script properties lost when passing pscustomobject to start-job script block?

On windows XP x64 (and I assume win2k3) powershell 2.0, passing an arraylist of pscustomobjects to start-job as argumentlist parameter passes the object in but scriptproperties just disappear from the object (confirmed by get-member). Note…
JorgeSandoval
  • 1,085
  • 1
  • 10
  • 20
2
votes
2 answers

PowerShell: using Compress-Archive with Start-Job won't work

I'm trying to use PowerShell to compress a bunch of video files on my H:\ drive. However, running this serially would take a long time as the drive is quite large. Here is a short snippet of the code that I'm using. Some parts have been…
Henry Yam
  • 23
  • 3
2
votes
1 answer

Start-Job Error: The term is not recognized as the name of a cmdlet, function, script file, or operable program

I have the following functions (these are simplified examples) function a {return 2} function b {$a=a; return $a+2} function c {$a=a; return $a*10} When I run the following codes Start-Job -ScriptBlock $Function:b -Name "test" Receive-Job -Name…
Alin
  • 350
  • 2
  • 13
2
votes
0 answers

Why does PowerShell's Start-Job sometimes finish without executing code?

I have been investigating an issue we see in some deployments at work. For background, we have multiple services deploying into Azure, and there is one main script which uses Start-Job to run concurrent sub-jobs. Most of the time this worked,…
2
votes
2 answers

How to run 2 methods simultaneously in PowerShell

I've got two functions, each of which I want to run in the background monitoring user behavior. The functions themselves work fine; however, I cannot seem to figure out how to invoke both of them to do work at the same time. In UNIX I would simply…
2
votes
0 answers

calling a user defined function inside the scriptblock in Powershell

I want to use multi-threading feature in powershell , hence I ventured into using Start-Job module. Below is the script that I am using to execute the block of code on multiple servers function get-isSystemUp($server,$serviceName) { …
SQLDoctor
  • 343
  • 7
  • 16
2
votes
1 answer

Passing Variables to Start-Job

I have to be missing something incredibly simple here. Here's a very basic script to illustrate what I'm trying: $Computers = @('comp1', 'comp2') $ScriptBlock = { New-Item "C:\Temp\$C.txt" -Force } Foreach ($C in $Computers) { Start-Job…
Tchotchke
  • 399
  • 1
  • 2
  • 18
2
votes
1 answer

How to use Start-Job in windows command while maintaining the state of current session

I am trying to run multiple jobs in parallel using Start-Job cmdlet. I have huge environment setup which is ignored because Start-Job runs the jobs in new session. Is there any way to maintain the environment settings. I want it to fork basically.
Pankaj Garg
  • 893
  • 2
  • 8
  • 15
2
votes
1 answer

Powershell - filtering WMIObject show two scripts result

im new beginner of powershell, now i have two script, one is get remote server's IPs, another one is get remote server's specific service start time, i need to show remote server's IP and specific service start time, can someone guide me how to…
Ted
  • 35
  • 4
2
votes
2 answers

Powershell Retrieve-Job gives "cannot index into null array error"

I am trying to test if two PC's are connected by using the following script $array ='PC1','PC2' for ($i=0; $i -lt $array.length; $i++) { Start-Job –Name TestConnection$i –Scriptblock { if(test-connection $array[$i] -count 1…
bIG_aL
  • 113
  • 1
  • 4
  • 12
2
votes
1 answer

Parameter in ScriptBlock not expanding properly

$foo = @("string.here") foreach ($num in $foo) { $s = { $WebClientObject = New-Object Net.WebClient IEX $WebClientObject.DownloadString('https://webserver/MyCommandlet.ps1') $temp = $args[0] MyCommandlet -Lhost…
Kant
  • 51
  • 3
2
votes
1 answer

Scriptblock works as Invoke-Command, but not as Start-Job

I have written a ScriptBlock that POSTs file uploads to a custom http server and saves the response to disk. It is intended to be used for testing said server and in addition to checking the correct response I'd like to run it in parallel to load…
Marian Aldenhövel
  • 677
  • 1
  • 6
  • 24
2
votes
1 answer

Run powershell script from within a powershell script

I have a perl script perl1.pl. Within the perl script I call a powershell script script1.ps1. In script.ps1 I call other script like script2.ps1 with local variables as parameters. I have prepared a powershell script script3.ps1. I want to run…
JustSam
  • 41
  • 1
  • 2
  • 3
2
votes
2 answers

PSSessionStateBroken with start-job -credential in scheduled task

The lines below work fine from a Powershell prompt, but fail from a scheduled task. $pass = gc C:\secrets\shhh.txt | convertTo-secureString $Cred = new-object -typeName System.management.automation.psCredential -argumentlist…
noam
  • 1,914
  • 2
  • 20
  • 26