Solved

Powershell GUI - ProgressBar

Posted on 2014-11-17
4
841 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

772 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