Solved

Powershell GUI - ProgressBar

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell switch statement 7 30
Powershell script for inactive computer accounts 3 20
Powershell Code 3 41
Script Error 3 11
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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