Datacopier for DaRT

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.
Locked
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Datacopier for DaRT

Post by apowershelluser »

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
Event with PBAR.png (15.49 KiB) Viewed 2493 times
Event with PBAR2.png
Event with PBAR2.png (24.78 KiB) Viewed 2493 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datacopier for DaRT

Post by jvierra »

Here is an old demo of a simplified Job tracker that uses both output to a control and a progress bar.
Attachments
Demo-PoorMansJobber.psf
(78.45 KiB) Downloaded 117 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datacopier for DaRT

Post by jvierra »

Please understand that you will be stepping the progress bar on every timer tick. You need to only step when the job results return a step completion.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Datacopier for DaRT

Post by apowershelluser »

Wouldn't a step completion be when the whole script is complete?

When I break it down in the ise
  1. $j = Start-Job -Name Robocopy -ScriptBlock {
  2. robocopy "C:\users\$user\desktop" "\\server1\$user\Desktop" /e
  3. Robocopy "C:\users\$user\Documents" "\\server1\$user\Documents" /e
  4. Robocopy "C:\users\$user\Downloads" "\\server1\$user\Downloads" /e
  5. }
  6.  
  7. $j
I only get one job
Jobs.png
Jobs.png (112.53 KiB) Viewed 2469 times
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Datacopier for DaRT

Post by mxtrinidad »

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.
Demo-SimpleJobTracker_wProgressbar.psf
(28.18 KiB) Downloaded 108 times
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Datacopier for DaRT

Post by mxtrinidad »

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.
:)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datacopier for DaRT

Post by jvierra »

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.
User avatar
apowershelluser
Posts: 194
Last visit: Fri Mar 22, 2024 4:38 am
Answers: 2

Re: Datacopier for DaRT

Post by apowershelluser »

Hey!!!

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datacopier for DaRT

Post by jvierra »

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)
Attachments
An Overview of the Sapien Job Tracker Framework.zip
(20.08 KiB) Downloaded 110 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Datacopier for DaRT

Post by jvierra »

This is how you are going to have to run the code. I did one step. You need to do all steps.

Code: Select all

$jobScript = {
    Param ($user)
    
    $Options = '/BYTES /E /R:0 /W:0'
    $Options2 = '/BYTES /R:0 /W:0'
    
    
    ##Destkop
    Start-Process Robocopy -ArgumentList @(
        "C:\users\$user\desktop",
        "\\FileShare\$user\Data\C\Users\$user\Desktop",
        $Options
    ) | Out-Null # required to suppress the output of the RC command
    if($LASTEXITCODE){ # exit code not 0
        Write-Warning "LASTEXITCODE was $LASTEXITCODE"
    }
    Write-Output 'Step 1'
    
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.
Locked