Page 1 of 1

GUI progress info for running tasks

Posted: Mon Apr 12, 2021 11:42 am
by cjtechie
I am working to create a GUI to run a number of computer configuration tasks. I have successfully configured the form and commands. The issue I am running into at this point is that some of the tasks take some time to complete. I am trying to enact some action that will inform the user that the tasks are running. At this point, clicking on the Complete Actions button will start the tasks and grey out the button to advise the user that it is running. I am struggling to add a visual cue for the user based on the running tasks. I am not picky on its implementation. Whether it be the button changing back to an actionable state, a progress bar of some sort, or output showing the completion of tasks. Any guidance or assistance on this would be greatly appreciated.
progress.txt
(2.19 KiB) Downloaded 110 times

Re: GUI progress info for running tasks

Posted: Mon Apr 12, 2021 12:25 pm
by cjtechie
  1. # Some dummy jobs for illustration purposes
  2. Start-Job -ScriptBlock{Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0 } -Name RemoteDesktop
  3. Start-Job -ScriptBlock{Set-TimeZone -Id "US Mountain Standard Time" } -Name MountainTime
  4. Start-Job -ScriptBlock{powercfg /change monitor-timeout-ac 10 | powercfg /change monitor-timeout-dc 10 | powercfg /change standby-timeout-ac 0 | powercfg /change standby-timeout-dc 15 } -Name PowerSettings
  5. Start-Job -ScriptBlock{gpupdate /force } -Name GroupPolicy
  6. Start-Job -ScriptBlock{Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000113}" } -Name SCCMUpdate
  7.  
  8.  
  9. # Get all the running jobs
  10. $jobs = get-job | ? { $_.state -eq "running" }
  11. $total = $jobs.count
  12. $runningjobs = $jobs.count
  13.  
  14. # Loop while there are running jobs
  15. while($runningjobs -gt 0) {
  16.     # Update progress based on how many jobs are done yet.
  17.     write-progress -activity "Events" -status "Progress:" `
  18.    -percentcomplete (($total-$runningjobs)/$total*100)
  19.  
  20.     # After updating the progress bar, get current job count
  21.     $runningjobs = (get-job | ? { $_.state -eq "running" }).Count
  22. }

Re: GUI progress info for running tasks

Posted: Mon Apr 12, 2021 12:26 pm
by cjtechie
I found the above code that works independently in the ISE but I am unsure how to integrate it into my existing form.

Re: GUI progress info for running tasks

Posted: Mon Apr 12, 2021 6:09 pm
by jvierra
To add in any code in a form you have to place the code in an event like a button click.

Re: GUI progress info for running tasks

Posted: Mon Apr 12, 2021 6:13 pm
by jvierra
To run asynchronous tasks consider the following article:
https://info.sapien.com/index.php/guis/ ... sive-forms