Solved

Powershell GUI - ProgressBar

Posted on 2014-11-17
4
1,020 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

732 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