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 5 years and 1 month 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.
mxtrinidad wrote: ↑Wed Feb 13, 2019 6:30 am
Every situation is different.
Your script need more care:
1. Everything that is repetitive can be converted to a function. ( function My-Robocopy{(param folder, options..)..} )
2. Use Try/Catch - if something happens to the Robocopy step, then what to do.
3. Need to build custom messages during your process. This will help to trace your process flow.
4. Use "run process" instead of job. This will help have more control over the code, and specially when debugging. You can't debug in a background job.
Progress Bar increment in a nutshell:
For example:
1. Initialize the Progress Bar
$progressbar1.Maximum = ##-Max number of Robocopy steps-###;
$progressbar1.Step = 1;
$progressbar1.Value = 0;
2. Moving to increment the progress bar after each Robocopy has completed:
$progressbar1.PerformStep();
Unfortunately, with how we want the data to be stored a function cannot be made.
The progress bar appears to be setup correct
Event with PBAR.png (15.49 KiB) Viewed 2493 times
Event with PBAR2.png (24.78 KiB) Viewed 2493 times
Strangely enough I've been working on a series of blog posts about Progress Bar. But, it will be release within one or two more weeks.
Now, my colleague JVierra provided a sample form using JobTracker. I change it a little to include both the progress bar and a RichTextBox controls.
I gave the form a little flexibility to select a folder and hardcode the file type (*.pdf) to list into the RichTextBox area.
This is still a demo sample but just enough to give an idea on how the progress bar will work with a backgrounf job scenario.
A similar example will be included in the upcoming blog post in a few months.
Again, Thanks to JVierra for providing the sample.
This is why it's better to do a run process instead of sending it to a background job.
You will need to loop thru the job and check for results in order to take the proper action. This involves in more code, which is not impossible, but will take you a little longer.
Hi Max. Good idea. A new article will be welcomed by all.
Yes. Using 'Start-Process would provide better control and more manageable code although, in this case it is not critical. Using a function to generalize the process would allow better code management and easier updates. The function should be included in the jobscript.
If this were my code I would start a sperate job for each copy and update the progress bar as each job completes. Set the "Maxvalue" to the total number of jobs.
You also need to check the errorlevel after each RoboCopy to report if it was successful.
So I looked over the new SimpleJobTracker_wProgressBar and it really helps break down items. However, in my example
I have 33 different folders, with varying files to grab and folders to grab
I think that's where some disconnect might be. If I was just moving say one folder to one place, I would just use the wonderful example in the spotlight article.
One thing to note the with new form. I would utilize the new layout of the Button-StartJob control set.
"If this were my code I would start a sperate job for each copy and update the progress bar as each job completes. Set the "Maxvalue" to the total number of jobs." ---- This was a thought.
I also missed this from earlier " I would just output numbers from the job. Output the step number and set the progress bar to that number." because this is exactly what I'm looking for, but I'm only returning one number, regardless if my jobscript has one folder to move with RC or multiple
The following old but still good document may help you to understand how the JobTracker works and how to correctly use it. In you case with outputting steps you must receive the step in the UpdateScript and only then increment the pbar. You will have to also check the job results in the completed step and do any final increments.
See if the following document helps you to understand how this works. (docx in zip file)
This topic is 5 years and 1 month 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.