0

I am pretty new to powershell (About 1 week in) and I am trying to create a tool for our helpdesk to import and export printers. The tool is running great except for the form is freezing when the code is being run.

To mitigate the freezing, I found that running it as a job gets the task done, however I am having 2 issues with it.

  1. I am not able to get the progress bar to increase 1 step as a result of the job completing.
  2. I am not able to pass variables to it. (I am not as worried about this as there is a ton of information on it, I just need to figure out the syntax for it. If you could help with that as well, that would be great though.)

    start-job -scriptblock {
    C:\Windows\system32\spool\tools\PrintBrm.exe -b -f \\filestore\$EXPORTPRINTERS.printerExport
    $progressbarexportprinters.PerformStep()
    $progressbarexportprinters.TextOverlay = "Printer Export Complete"
    }
    

I found a solution for this. the form is still freezing, but I can show movement on the progress bar. Which will be good enough.

C:\Windows\system32\spool\tools\PrintBrm.exe -r -f \\filestore\$EXPORTPRINTERS.printerExport | out-string -Stream | foreach-object {
    $richTextBox1.lines = $richTextBox1.lines + $_
    $richTextBox1.Select($richTextBox1.Text.Length, 0)
    $richTextBox1.ScrollToCaret()
    $progressbaraddprinters.PerformStep()
}
user3585839
  • 1,459
  • 3
  • 12
  • 18
  • Can you show your code for where `$progressbarexportprinters` is defined? Also, pass variables to what, the progress bar? – TheMadTechnician Apr 29 '14 at 16:14
  • I am using Powershell studio so I do not have any defining code. The progress bar starts at zero and each step is 10. The maxvalue is 80. Also, the passing of variables is referring to passing them to the "Start-job". It will currently complete the job, but it will not have a filename. – user3585839 Apr 29 '14 at 16:57
  • The defining code is in there, you just have to open the script in the PowerShell ISE, or in a text editor of some sort. If you don't even know your own script you can't expect us to be able to help fix errors with it. – TheMadTechnician Apr 29 '14 at 16:59
  • Is this what you are looking for? $progressbarexportprinters.ForeColor = 'Lime' $progressbarexportprinters.Location = '186, 164' $progressbarexportprinters.Name = "progressbarexportprinters" $progressbarexportprinters.Size = '156, 22' $progressbarexportprinters.TabIndex = 1004 $progressbarexportprinters.Visible = $False $progressbarexportprinters = New-Object 'SAPIENTypes.ProgressBarOverlay' – user3585839 Apr 29 '14 at 17:04
  • 2
    Oh, you're using PrimalForms or some such Sapien product. Ok, I understand the issue as to why you wouldn't know your code, but unfortunately I am unable to give you the answers you want. You may be better off asking over on the Sapien forums because while the underlying code may be powershell the usage of their product isn't. – TheMadTechnician Apr 29 '14 at 17:10
  • The `Job` executes in a different `Runspace` and will therefore not have access to everything that the variables in the script scope in the script execution runspace. I do not have any experience with the Sapien products, but I guess what you need to do is that the script which starts the jobs should periodically use `Get-Job` to see when the jobs finish, and when they do finish it can 'step' the progressbar. So it would be the script which creates the job which will step the progressbar, not the jobs themselves (since they do not have access to the progressbar). – Robert Westerlund Apr 29 '14 at 22:16

0 Answers0