Page 1 of 1

JobProgressBar

Posted: Thu Oct 15, 2015 12:13 pm
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

JobProgressBar

Posted: Thu Oct 15, 2015 12:13 pm
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 ***

Re: JobProgressBar

Posted: Thu Oct 15, 2015 2:13 pm
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

Re: JobProgressBar

Posted: Fri Oct 16, 2015 7:58 am
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

Re: JobProgressBar

Posted: Fri Oct 16, 2015 1:30 pm
by jvierra

Re: JobProgressBar

Posted: Fri Oct 16, 2015 1:35 pm
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