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.
User avatar
angelofstealth
Posts: 37
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Thu May 04, 2017 12:04 pm

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,

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu May 04, 2017 1:25 pm

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: 37
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Fri May 05, 2017 5:56 am

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: 20
Joined: Mon May 01, 2017 8:28 pm

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

Post by MarvelManiac » Fri May 05, 2017 8:25 pm

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: 37
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Tue May 09, 2017 8:11 pm

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 15 times

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed May 10, 2017 3:06 am

to do what you are trying to do you will have to use the JobTracker custom control set.

User avatar
angelofstealth
Posts: 37
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Wed May 10, 2017 7:10 am

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 11 times

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed May 10, 2017 10:23 am

You don't have a tracker. Start by building the example and testing until you understand how it works.

User avatar
angelofstealth
Posts: 37
Joined: Wed Feb 13, 2013 4:26 pm

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

Post by angelofstealth » Wed May 10, 2017 1:56 pm

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.)

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Wed May 10, 2017 2:34 pm

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.

Locked