Solved

Powershell GUI - ProgressBar

Posted on 2014-11-17
4
706 Views
Last Modified: 2014-11-20
Hi, I am using AdminScriptEditor to make a GUI front-end for PowerShell.    
When I click a button, it will run the command:    
Get-MoveRequestStatistics -identity $user | select PercentComplete    

Which will return a number to indicate percentage (i.e. 53)

If I have a ProgressBar on the form, how can I have it take the number from the value returned from above (i.e. 53) and update the progress bar accordingly? And have it refreshing periodically?

#~~< progressMove >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$progressMove = New-Object System.Windows.Forms.ProgressBar
$progressMove.Location = New-Object System.Drawing.Point(7, 175)
$progressMove.Size = New-Object System.Drawing.Size(224, 23)
$progressMove.TabIndex = 9
$progressMove.Text = ""

Open in new window

0
Comment
Question by:garryshape
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 40448151
You can try taking the value from move command and feed it as progress bar value.

$Percent = (Get-MoveRequestStatistics -identity $user).PercentComplete
$progressMove.Value = $Percent
0
 

Author Comment

by:garryshape
ID: 40448252
Yeah that works I wonder if I can add code around it though so that it keeps refreshing the progressbar and other elements every few seconds until 100% complete
0
 
LVL 16

Assisted Solution

by:Rajitha Chimmani
Rajitha Chimmani earned 500 total points
ID: 40448294
You could use a do while loop. I dont know if I have to enter the complete code within the loop or just the two lines that I gave in my last comment. I have not got time to test it.

do{
$Percent = (Get-MoveRequestStatistics -identity $user).PercentComplete
$progressMove = New-Object System.Windows.Forms.ProgressBar
$progressMove.Location = New-Object System.Drawing.Point(7, 175)
$progressMove.Size = New-Object System.Drawing.Size(224, 23)
$progressMove.TabIndex = 9
$progressMove.Text = ""
$progressMove.Value = $Percent
}while ($Percent -le 100)
0
 

Author Comment

by:garryshape
ID: 40448804
Only thing I'm not sure on is if the Do While will be a good idea since the progress bar's going to move along really slowly, likely hours, and the window/script might freeze up.

How could I incorporate a "timer" to say, after I push the button, periodically (like every 30 seconds or so), re-run the command to get the value and update the progressbar.value (to reflect that new percent value we got)?
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
A procedure for exporting installed hotfix details of remote computers using powershell
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now