GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by angelofstealth »

Goal:
1) read in events from Active Directory into an array
2) Process each object in that array while perform and invoke command to a remote computer, updating the progress bar at the sametime.
- How can I combine the loop of the computer objects with the indexing of the progress bar at the sametime using the tracker.

I have read these articles:
https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
https://www.sapien.com/blog/2011/07/15/ ... ive-loops/

Note:
The reason why i looked at these articles and asking the question is i want to stop the freezing form. My GUI/EXE is completed for what I want it to do, just would like to resolve this.
Right now it seems the example is just for a single call around the progress bar vs multiple/loop, i know I am probably missing something. Any help in the right direction would be great.
Thanks,
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by jvierra »

I am sorry but it is not possible to understand what you are asking.

I suggest that you download the example code a run it . Use debugger to step through until you understand how the tracker works. Your job must have incremental output for this to be usable or you must guess at a time and increment accordingly.

If the job contains a loop then output something on each iteration of the loop.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by angelofstealth »

I think i know what i need to do to get to what i want,

Basically want each object from an array (computer AD objects) be the progress bar update, inside the progress bar i presume the jobtracker/job will perform the work.

I will run through the debug, see if i can come up with a solution. Thanks,
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by MarvelManiac »

angelofstealth wrote:I think i know what i need to do to get to what i want,

Basically want each object from an array (computer AD objects) be the progress bar update, inside the progress bar i presume the jobtracker/job will perform the work.

I will run through the debug, see if i can come up with a solution. Thanks,
If you right click on the progressbar and choose "view spotlight article", look at
Progressbar1.maxium = files.count
Progressbar1.step = 1

Etc

Should give you exactly what you want
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by angelofstealth »

Thanks for the help MarvelManiac, pointed me in the right direction. My code will now update the datagridview with the computer objects without freezing the form. Much appreciated for that.

Follow up question:
How can i make the Get-ADComputer call not freeze my form if it is taking a while. I know with the jobtrackers i was able to pass calls to it to perform routines. If i use Start-Job with a -Scriptblock, in the scriptblock i have my Get-ADComputer command, then after that Start-Job call i use the stored variable with the wait-job and it doesn't seem to wait for it to finish. Can't find anything on the forums in regards to using Get-AdComputer with jobs/responsive forms information. I have attached my code so far, not everything is programmed yet, but the Process/Cancel/Exit buttons do whats required.

Thanks,
Attachments
ProcessLoop v1.0.psf
(50.82 KiB) Downloaded 170 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by jvierra »

to do what you are trying to do you will have to use the JobTracker custom control set.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by angelofstealth »

I added the JobTracker with the parameters/code to the form, running into the following error. Attached updated code.

Code/Tracker
$ADFilter = 'OperatingSystem -Like "Windows *Server* *2008*" -and enabled -eq $true'
Add-JobTracker `
-Name "ADLookUp" `
-JobScript {
PARAM ($ADFilter)
Get-ADComputer -Filter $ADFilter -Properties Name, OperatingSystem, OperatingSystemVersion, IPv4Address, Enabled | Sort Name
Start-Sleep -Seconds 5
} `
-CompletedScript {
PARAM($job)
$results = Receive-Job -Name "ADLookUp"
$v_AD_AllWinServers = $results
}`
-ArgumentList $ADFilter

Error:
ERROR: You cannot call a method on a null-valued expression.
ProcessLoop v1.0.psf (534, 4): ERROR: At Line: 534 char: 4
ERROR: + $timerJobTracker.Start()
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : InvokeMethodOnNull
ERROR:
Attachments
ProcessLoop v1.0.psf
(55.08 KiB) Downloaded 157 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by jvierra »

You don't have a tracker. Start by building the example and testing until you understand how it works.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by angelofstealth »

I added the tracker to my code, not receiving an errors now. No results are being returned, i pipe my completedscript/receive-job, results are empty.

$timerJobTracker = New-Object 'System.Windows.Forms.Timer'
$timerJobTracker.Interval = 2500
$timerJobTracker.add_Tick($timerJobTracker_Tick)


Can anyone assist? (FYI..review the example not a helpful response.)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form

Post by jvierra »

I cannot review code not posted. If you cannot make the example work or understand it then it will be very hard for you to know how to use the JobTracker.

The JobScript has to output something. The Update Script has t return the current job results and so something with it. The JobComplete script is where you would retrieve the final results and do what ever you need.

All of this is clearly explained in the articles and the example shows clearly how to use the Tracker.

The JobScript cannot reference any controls or variables in the form.

Start by testing your jobScript as a job under PowerShell CLI until you get it to return what you need. This will guarantee that there are no dependencies on the form.

Programming forms is a difficult learning experience. It is not a linear system but is completely event driven. Adding a job adds a further issue of a second thread. Once you learn what all of these things are and how they behave you will find that this is really easier than it seems.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked