Progress bar when running PS cmdlet

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
harringg
Posts: 18
Last visit: Wed Sep 08, 2021 11:37 am

Progress bar when running PS cmdlet

Post by harringg »

New to WinForms and progress bars.

I've got a button that installs RSAT tools (when the WinForm is run as Admin).

When running the command in the ISE (VSCode) it displays a progress bar in VSCode. Is it possible to have that shown in the WinForm? I've added progressbaroverlay1 to the Form at the bottom, but not sure how to "call" it (if even possible). I can add a loop function to check if it's installed and when it is, report via a pop-up, but a progress bar would be cleaner.

Code: Select all

$buttonInstallRSAT_Click={
	#TODO: Place custom script here
	Get-WindowsCapability -Name "RSAT*" -Online | where-object { $_.name -like "Rsat.NetworkController.Tools~~~~0.0.1.0" } | Add-WindowsCapability -Online
}

jvierra
Posts: 14927
Last visit: Sat Sep 18, 2021 12:32 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Progress bar when running PS cmdlet

Post by jvierra »

Again you have too little useful information to know what your issue is.

See the online examples for how to use a ProgressBar.

User avatar
JohnTitor
Posts: 166
Last visit: Fri Aug 13, 2021 3:06 pm

Re: Progress bar when running PS cmdlet

Post by JohnTitor »

Did you ever figure this out? I'm also curious as I'm facing a similar issue.

User avatar
Lembasts
Posts: 334
Last visit: Tue Sep 14, 2021 4:25 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Progress bar when running PS cmdlet

Post by Lembasts »


User avatar
harringg
Posts: 18
Last visit: Wed Sep 08, 2021 11:37 am

Re: Progress bar when running PS cmdlet

Post by harringg »

I've got a progress bar working for "progress scripts". I was looking to output the progress bar when running "import-module activedirectory", like it does in the ISE.

And same with my OP question, that action, in the ISE has a "progress bar", just hoping to capture in the form.

In WINFORMS when first launching the form, it pops-out in a separate window (natively, nothing I've added to my scripts). Just hoping I could bring that "into" the actual form itself. May not be possible.

jvierra
Posts: 14927
Last visit: Sat Sep 18, 2021 12:32 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Progress bar when running PS cmdlet

Post by jvierra »

You can't with the AD module because it will be preloaded by the time the form executes. Import-Ad only takes a sedcond or less. If you import it on the froms "Shown" even then you may get a ProgressBar on slower computers but you won't get it on the "Load" even or earlier.

Locked