Redirect Process Output - Dism - ProgressBar

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.
This topic is 4 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Redirect Process Output - Dism - ProgressBar

Post by localpct »

Hello,
With DISM, it provides us a nice percentage of the process output:

Code: Select all

[===========================76.2%============              ] 
[===========================77.1%============              ] 
[===========================78.1%=============             ] 
[===========================78.9%=============             ] 
[===========================79.9%==============            ] 
[===========================80.8%==============            ]
How can I extract the percentage and apply it to a progress bar on the update step?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Redirect Process Output - Dism - ProgressBar

Post by jvierra »

What have you tried?
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Redirect Process Output - Dism - ProgressBar

Post by localpct »

RemoteDism.psf
(38.6 KiB) Downloaded 185 times
I had to regex most of the items ( line 91 )
Take what was left so if it's at 5.0%, it returns 50, if it's at 99.9 percent, it returns 999

Line 115 in the updatescript
$progressbar1.Value = $richtextbox1.Text
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Redirect Process Output - Dism - ProgressBar

Post by jvierra »

You need to use a proper RegEx. The RegEx you are using is removing the decimal point.

Example:

Code: Select all

if('[===========================78.1%=============             ]' -match '(\d+.\d+)'){$matches[1]}
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Redirect Process Output - Dism - ProgressBar

Post by localpct »

I didn't think the Pbar can handle the decimals? that's why I did it
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Redirect Process Output - Dism - ProgressBar

Post by jvierra »

Then you can just do this:

Code: Select all

$s = '[===========================78.1%=============             ]'
if($s -match '(\d+)'){[int]$matches[1]}
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Redirect Process Output - Dism - ProgressBar

Post by localpct »

So I just did this and it appears to be working

Code: Select all

RedirectOutputScript			  = {
			# Use $_.Data to access the output text
			$richtextboxOutput.AppendText($_.Data)
			$richtextboxOutput.AppendText("`r`n")
			if ($_.Data -match '(\d+)')
			{
				$progressbar1.Value = [int]$matches[1]
			}
This topic is 4 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked