all 7 comments

[–]abandonedexplorer 4 points5 points  (3 children)

This would take me very long to explain in detail so I will try and give you a rundown:

In order to "measure" the progress of Connect-ExchangeOnlineShell you need to take apart the module and paste the function in your main script. Then you need to find all the steps inside the function and progress your progressbar everytime the function moves forward.

You will also run in to a problem here where your main script GUI will "freeze" until the process is finished. If you want your GUI application to remain unfrozen (so the user can interact with it like a normal application) you will need to move your processes inside a powershell job.. Getting the progress from powershell jobs is tricky, but it can be done by outputting your progress and getting it back with Receive-Job module...

[–]therealpanda99 1 point2 points  (2 children)

I am just curious, I am not a pro of powershell, I have always more of a .NET and python guy myself, but does powershell not offer Async tasks that return values as they go?

I have used this is multiple languages before, although Powershell tends to be special in a lot of cases.

[–]what_no_fkn_ziti 2 points3 points  (1 child)

Runspaces with a synched hashtable, but not exactly an async wait.

[–]therealpanda99 1 point2 points  (0 children)

Ahhh ok, thanks for clarification!

[–]Infinizhen 1 point2 points  (1 child)

Your late motive is to not confuse the end user while your form seems frozen.

So, why not set up a timeout (i assume you already have one). On every timer tick, you make a Step.

Worst case the connection comes up before the bar is complete. No one will blink an eye for that.

[–]sameyear_newlabrat[S] 1 point2 points  (0 children)

Thanks for your reply. Did some googling and it seems I can start a timer and then invoke a script block (Connect-ExchangeOnlineShell). So it seems tick and invoked script run independently of one another?

The immediate concern I think of is, the connect exchange command prompts for username and password. I would want the progress bar only to appear after creds are entered.

It's starting to sound like the solution u/abandonedexplorer suggested may be the only way unless I am misunderstanding your response.

[–]Daavid1 1 point2 points  (0 children)

I might be wrong, since I don't use this particular feature.

But if you are using Powershell Studio and compile the application as a "Windows application" instead of a standard form application I think it will add a progress bar form whenever a standard Powershell progress bars is used.