Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/html/powershellpower.com/page_parts/question.php on line 78

Warning: Use of undefined constant page_id - assumed 'page_id' (this will throw an Error in a future version of PHP) in /var/www/html/powershellpower.com/page_parts/question.php on line 90

Notice: Undefined index: page_id in /var/www/html/powershellpower.com/page_parts/question.php on line 90

Warning: Use of undefined constant detail - assumed 'detail' (this will throw an Error in a future version of PHP) in /var/www/html/powershellpower.com/page_parts/question.php on line 91

Warning: Use of undefined constant answer - assumed 'answer' (this will throw an Error in a future version of PHP) in /var/www/html/powershellpower.com/page_parts/question.php on line 92

Warning: Use of undefined constant link - assumed 'link' (this will throw an Error in a future version of PHP) in /var/www/html/powershellpower.com/page_parts/question.php on line 93

Warning: include(title_processing.php): failed to open stream: No such file or directory in /var/www/html/powershellpower.com/page_parts/question.php on line 114

Warning: include(): Failed opening 'title_processing.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/powershellpower.com/page_parts/question.php on line 114

Is it possible to multithread or run a script on hundreds of computers at the same time

How to multithread in powershell

I have found using foreach loops in powershell does the task well enough but when it comes to working with many remote servers and computers I need a much faster approach as this can only process one computer at a time, is it possible to multithread a script

Answer

This is one method in which you can create a new job for each computer in a list, there is a far more refined way than this, if you are interested click the read more button below.
The first job is to pipe from a list, you can use a csv or import them straight from AD.
Next we create a script-block which will execute on ever computer in the list.
The start-job will take care of the multithreading as the script fires the command and loop onto the next cycle of the foreach loop.
Finally we have a loop which will check on the jobs and keep the script active until they have all been processed

$computers = get-adcomputer -filter * | % {

### script###
$ScriptBlock = {
param($pipelinePassIn)
remove-item -path C:\test.txt
}

### multithread ###
Start-Job $ScriptBlock -ArgumentList $_
}



### Loop-until-jobs-finished ###
While (Get-Job -State "Running")
{
Start-Sleep 5
write-host "Jobs in progress - please wait" -foreground color red
}


Warning: mysqli_result::fetch_assoc() expects exactly 0 parameters, 1 given in /var/www/html/powershellpower.com/page_parts/question.php on line 174
Comments

Notice: Undefined variable: commentno in /var/www/html/powershellpower.com/page_parts/question.php on line 318

Notice: Undefined variable: page_id in /var/www/html/powershellpower.com/page_parts/comments.php on line 9

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in /var/www/html/powershellpower.com/page_parts/comments.php:16 Stack trace: #0 /var/www/html/powershellpower.com/page_parts/question.php(327): include() #1 /var/www/html/powershellpower.com/questions/is_it_possible_to_multithread_or_run_a_script_on_hundreds_of_computers_at_the_same_time.php(2): include('/var/www/html/p...') #2 {main} thrown in /var/www/html/powershellpower.com/page_parts/comments.php on line 16