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,
GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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.
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.
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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.
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.
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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,
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,
- MarvelManiac
- Posts: 63
- Last visit: Thu Sep 13, 2018 3:40 pm
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
If you right click on the progressbar and choose "view spotlight article", look atangelofstealth 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,
Progressbar1.maxium = files.count
Progressbar1.step = 1
Etc
Should give you exactly what you want
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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,
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 171 times
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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:
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 158 times
- angelofstealth
- Posts: 69
- Last visit: Wed Sep 28, 2022 10:04 am
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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.)
$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.)
Re: GUI: Progress Multiple Com Objects/Progress Bar - Responsive Form
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.
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.