JobProgressBar

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.
Locked
User avatar
gutihz
Posts: 38
Joined: Fri Mar 20, 2015 1:42 pm

JobProgressBar

Post by gutihz »

Hi Everyone,

I saw David Corrales's post on "Creating Responsive Loops".
https://www.sapien.com/blog/2011/07/15/ ... ive-loops/

It's a great article. Very informative. I'm planning to use to call functions to copy things, however I'm kind of stuck. I can't figure out how to use FOREACH loop, pass the function, wait for the first job to complete then update the progress bar.

Here is my function. I have 5 of these. Anyone help would be appreciated.

Code: Select all

Function Copy-1
	{
		Try
		{
			$Source = "C:\TestFrom\1"
			$Destination = "C:\CopyTo"
			IF (-not (Test-Path $Destination))
			{
				New-Item -Type Directory $Destination -Force
			}
			Copy-Item $Source -Recurse -Destination $Destination -Container -Force
		}
		Catch
		{
			"$Error[0].ToString()" | Out-File "C:\backup\job.log"
			
		}
		$Source = $null
		$Destination = $null
		
	}

1. Product, version and build - PowerShell Studio 2015, 4.2.93
2. 32 or 64 bit product - 64-bit
3. Operating system, e.g.- Windows 7 64-bit
4. Attach a screenshot, if applicable - N/A
5. Attach logs, crash reports, etc., in a ZIP file - N/A

User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

JobProgressBar

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, gutihz.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PowerShell Studio 2014, Version & Build: 4.1.71. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: JobProgressBar

Post by davidc »

[POST MOVED BY MODERATOR]

If the command is handling the recursion you will not be able to provide progress for each individual item. To do this, you would have to copy each item individually.

David
David
SAPIEN Technologies, Inc.

User avatar
gutihz
Posts: 38
Joined: Fri Mar 20, 2015 1:42 pm

Re: JobProgressBar

Post by gutihz »

Hi David,

Thanks for the reply.

I don't think I follow you. Would you be able to give me an example?
I tried doing :

Code: Select all


$selected = @("Test-1", "Test-2", "Test-3")

$buttonStartJob_Click= {
	
	$buttonStartJob.Enabled = $false
	#Create a New Job using the Job Tracker
	Foreach ($i in $selected)
	{
		IF ($i -eq "Test-1")
		{
			Add-JobTracker -Name "$i" `
		 -JobScript {
Try
      {
         $Source = "C:TestFrom1"
         $Destination = "C:CopyTo"
         IF (-not (Test-Path $Destination))
         {
            New-Item -Type Directory $Destination -Force
         }
         Copy-Item $Source -Recurse -Destination $Destination -Container -Force
      }
      Catch
      {
         "$Error[0].ToString()" | Out-File "C:backupjob.log"
         
      }
      $Source = $null
      $Destination = $null

ELSEIF($i -eq "Test-2")
		{
			Add-JobTracker -Name "$i" `
		 -JobScript {
Try
      {
         $Source = "C:TestFrom2"
         $Destination = "C:CopyTo"
         IF (-not (Test-Path $Destination))
         {
            New-Item -Type Directory $Destination -Force
         }
         Copy-Item $Source -Recurse -Destination $Destination -Container -Force
      }
      Catch
      {
         "$Error[0].ToString()" | Out-File "C:backupjob.log"
         
      }
      $Source = $null
      $Destination = $null

And so forth. But it doesn't wait for the first job to finish and update the progress bar. Everything runs at the same time. Anyway I can adjust the update or completed script section to do this?

Thanks

jvierra
Posts: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

Re: JobProgressBar

Post by jvierra »


jvierra
Posts: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

Re: JobProgressBar

Post by jvierra »

You can also use -PassThru on the copy to force output as each file is copied.
PowerShell Code
Double-click the code block to select all.
Copy-Item $Source -Recurse -Destination $Destination -Container -Force -PassThru

Locked