3

At my job, I do a lot of installing and reinstalling of the same software. I wrote a script in Powershell to silently install everything for me, which works great. However, because it's silent there is no feedback and anyone else who uses the program thinks it's either stalled or not running.

I'm trying to find a way to have it run the silent installs as well as load a status bar. I've been working with this code for the progress bar:

for ($i = 1; $i -le 100; $i++ ){write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i; Start-Sleep -Milliseconds 10}; .\Untitled11.ps1

But for the life of me, I can't get it to run at the same time as the installs. I've tried a bunch of different commands like background launching and parallel running but the status bar always run after or before the install depending on where I place it.

Any ideas on how I can have both the install and a status bar to run at the same time? I'm not married to the status bar code, it's just the one I've been working with. So if there is an easier way or more adaptive code, I'm open to it.

Wes Sayeed
  • 14,102
Maizzer
  • 31
  • 1
  • 2

3 Answers3

1

You will not be able to see live progress of an application's install using this cmdlet. Write-Progress is designed to depict the status of a "running command or script". There is no way for this cmdlet to gather installation progress information.

As mentioned in the comments, it may be more attractive to issue messages to alert the user of the script's progress.

"This will not detect errors, but give a general sense of completion."

"Running Program A (step 1 of 3)..."
    (run_program_A)
"Program A finished."

"Running Program B (step 2 of 3)..."
    (run_program_B)
"Program B finished."

"Running Program C (step 3 of 3)..."
    (run_program_C)
"Program C finished."

"Finished."
root
  • 3,920
1

Write-Progress does not have any real insight into the installation progress of your application. It's just a dumb indicator that you have to increment yourself every time you want it to update.

If you are spawning multiple MSI/EXE files as part of your installation progress, you have to insert a Write-Progress after every step of the process. You can either populate an array with the name of each MSI/EXE command line and loop through that, or you can just use multiple Write-Progress statements using the same ID number.

Also, the progress bar can only be incremented when a command finishes executing. If you're farming out the install to another script, that constitutes one command and you won't get incremental progress. You need to make your individual components part of the same script. Along those lines, this also won't work if your install is one big program that takes a long time to run.

Wes Sayeed
  • 14,102
0

Create job that will do it. This will enable running asynchronously instead of synchronously, then once installed stop and remove the job.

daren
  • 1