two background jobs colision

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
noescape
Posts: 16
Joined: Wed Apr 22, 2015 4:57 am

Re: two background jobs colision

Post by noescape » Wed Jan 13, 2016 6:09 am

jvierra wrote:
noescape wrote:Thanks for useful information, it makes sense. I figured it out myself but I'm glad it was the right place to stop the timer.
Here is how to run a continuous background ping against multiple computers. It will run until you stop the job. You can use a timer to poll the job and display/update the status of the computers. Other tasks can just test the status. I use read only checkboxes to display status and se the color. If checked the computer is online and responding.
  1. workflow pingall  {
  2.  
  3.     param([string[]]$computers)
  4.  
  5.     while(1){
  6.  
  7.         foreach -parallel($c in $computers) {
  8.  
  9.             Test-Connection $c -Count 1
  10.  
  11.             sleep 2
  12.  
  13.         }
  14.  
  15.     }
  16.  
  17. }
  18.  
  19. pingall 'omega', 'w8test', 'alpha'
  20.  
  21. pingall 'omega', 'w8test', 'alpha' -asjob -JobName PingAll

Perfect, I was experimenting with parallel workflow before but couldn't get it to update my form controls correctly. In my form I also use a datagridview with readonly checkbox column to display status of queried stations so that should be easy to set up.
Thanks a lot for this piece of code.

Regards,

Thomas

Locked