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.
- I am not able to get the progress bar to increase 1 step as a result of the job completing.
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()
}