Solved

Powershell GUI - ProgressBar

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

19 Experts available now in Live!

Get 1:1 Help Now