locked
how to add progress bar in powershell GUI RRS feed

  • Question

  • Hello Team,

    I Have created PowerShell GUI Tool.It is working as excepted. Thanks to JRV who helped me a lot

    Now I want add progress bar pop up while getting result. I am using write-host command. But I want PowerShell pop with progress bar.can some one please advice. 

    #####################################################

    function Get-hotfixes
    {
       [CmdletBinding()]
       [OutputType([int])]
       Param
       (
         
          [Parameter(Mandatory=$true,
          ValueFromPipelineByPropertyName=$true,
          Position=0)]
          $computer
       )
     
       Begin
       {
       }
     
       Process
       {
          $win32_product = @(get-wmiobject -class  ‘Win32_QuickfixEngineering’   -computer $computer)
     
          foreach ($app in $win32_product){
             $applications = New-Object PSObject -Property @{
             Name = $app.Name
            Description  = $app.Description
             HotFixID=$app.HotFixID
             InstalledBy=$app.InstalledBy
             InstalledOn=$app.InstalledOn
             Computername=$app.PSComputerName
             }
     
             Write-Output $applications | Select-Object Computername,Description,InstalledBy, InstalledOn
          }
       }
     
       End
       {
       }
    }

    function Get-update {
     $outputBox.Clear()
     $outputBox.Text ="Getting windows updates list Please wait"
     $computers=$InputBox.lines.Split("`n")
     $date =Get-Date
     $ct = "Task Completed @ " + $date
     foreach ($computer in $computers)
     {
     $m =  Get-hotfixes  $computer | ft -AutoSize|Out-String
     Write-Host $m | ft -AutoSize
     
     $outputBox.Appendtext("{0}`n" -f $m +"`n $ct"  )
     }

       }

    ####function end###\

    output in gui

    • Moved by Bill_Stewart Monday, October 2, 2017 9:52 PM Unanswerable drive-by question
    Monday, August 21, 2017 2:43 PM

All replies

  • https://mcpmag.com/articles/2014/02/18/progress-bar-to-a-graphical-status-box.aspx

    Monday, August 21, 2017 2:49 PM
  • Write-Progress, when executed from a form, will pop up a GUI progress box.

    help write-progress -full


    \_(ツ)_/

    Monday, August 21, 2017 5:08 PM
  • Hi JRV Thanks for your response

    I am using belwo one as an example.it is working fine

    but how can I add a progress  GUI bar to this

    ##########################

    $servers = Get-Content C:\servers.txt

    foreach($ser in $servers)
    {
    $col =Get-HotFix  -ComputerName $ser

    For($i = 1; $i -le $col.count; $i++)
    { Write-Progress -Activity "Gathering updates" -status "Please wait"` -percentComplete($i / $col.count*100)}
    $col
    }

     ################################################################
     $objProgressBar = New-Object System.Windows.Forms.ProgressBar
     $objProgressBar.Value = 0
     $objProgressBar.Location = New-Object System.Drawing.Size(12,97)
     $objProgressBar.Size = New-Object System.Drawing.Size(260,14)
     $objForm.Controls.Add($objProgressBar)
     $objForm.Topmost = $True
     $objForm.Add_Shown({$objForm.Activate()})

    ####################################################################


    Friday, August 25, 2017 4:46 AM
  • Like this:

    $progressbar.Maximum = $col.count
    For ($i = 1; $i -le $col.count; $i++) {
    	$progressbar.Value = $i
    }
    https://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar(v=vs.110).aspx


    \_(ツ)_/


    • Edited by jrv Friday, August 25, 2017 6:11 AM
    Friday, August 25, 2017 6:10 AM