Thursday, June 12, 2025
HomePowershellEnjoying with Background Jobs – SID-500.COM

Enjoying with Background Jobs – SID-500.COM


PowerShell

On this weblog submit, I’d like to provide you a number of examples associated to PowerShell Background Jobs to construct upon. Let’s bounce in.

Let’s say I need to ping a number of computer systems. This consumes time. So I need that this activity runs within the background as a PowerShell background job.

First, I create some laptop names.

$namen = @(
'orf.at'
'sid-500.com'
'8.8.8.8'
'9.9.9.9'
)

Then I’ll do a fast verify whether or not there are another jobs working within the background.

Then I begin my background job “ping” to ping all laptop names in $namen. Word that I exploit the $utilizing variable to have the ability to use $namen, which is a world variable and subsequently out of the scope of the script block.

Begin-Job -Title 'ping' `
-ScriptBlock {Check-Connection -ComputerName $utilizing:namen}

A fast look with Get-Job reveals that this job is at present working.

In any case, it’s price mentioning that after the job has completed, the end result is just not output and that – above all – the result’s solely output as soon as, except you utilize the -Maintain parameter.

Obtain-Job -Title ping
Obtain-Job -Title ping -Maintain # don't delete output

That’s it. I hope I used to be capable of shed some gentle on PowerShell background jobs.

Printed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2023], IT-Coach, IT-Marketing consultant, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments