6 Replies Latest reply on Jan 6, 2009 12:16 PM by dmaster

    Progressbar problem when running scriptblocks

    dmaster Expert
    VMware EmployeesvExpert

       

      Hello all,

       

       

      I created a simple form with a button and a progressbar with PrimalForms.

       

       

      When i click the button, a powershell script will be started.

       

       

      In my example i want to set the network security policies for a couple of esx servers.

       

       

      Everything works fine when i click on the button. The problem is that i don't see the progressbar increasing.

       

       

      only when all esx servers have been done i see the progressbar at it's maximum value.

       

       

      It should be nice that i also see the progressbar increasing when the sciptblock is running.

       

       

      i attached the script below.. who can assist ?

       

       

      Thanx

       

       

       

       

       

       

       

       

        • 1. Re: Progressbar problem when running scriptblocks
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          The Value property of a ProgressBar gets or sets the current position of the progress bar but doesn't force a redraw.

          You should use the Increment method to see the bar progress.

           

          Attached an updated version of your script with the Increment method.

           

          Btw there was an error in the Disconnect-VIServer cmdlet.

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          1 person found this helpful
          • 2. Re: Progressbar problem when running scriptblocks
            dmaster Expert
            vExpertVMware Employees

             

            Hi LucD,

             

             

            Thanx for helping  out. I tried your modified version of the script but still the same results.

             

             

            when executing the script, the form is not updating (redraw).. when the scripts has been finished the progressbar is completely full..

             

             

            see screenshots... any clue what is going wrong now, do i still have to do something with  $progressbar1.value ?

             

             

             

            p.s. what is / was wrong with the disconnect line ?

             

             

            Regards,

             

             

            Dennis

             

             

            • 3. Re: Progressbar problem when running scriptblocks
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              First, apologies for the Disconnect-VIserver remark.

              That was ok, I must have made a mistake when copying your script to my editor.

               

              The Increment method works for me.

              See attachments.

              I'm tested with PS v1 and VITK 1.0 build 113525.

              Could you perhaps say from where you run the script ?

              I tested from within my editor (PS+) and from the VITK promtp, both worked.

               

              Perhaps you could try to insert "Write-Host $progressBar1.value" after the $progressBar1.increment(1) statement.

              You should see the values 1,2,3.

               

                   

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Progressbar problem when running scriptblocks
                dmaster Expert
                vExpertVMware Employees

                Hi LucD,

                 

                 

                I am testing also with PS v1 and VITK 1.0 build 113525. With the difference that is also use powergui script editor.

                I tested the script on a computer of a college of mine, he also has the same issues ?

                 

                 

                The script will run when someone clicks on the button "Run Script".

                 

                Every time the form looks to freeze when clicking on the "Run Script" button.

                 

                 

                When i change this script from (the location of the line $progressBar1.increment(1)):

                 

                $x = 1

                do {$x;

                $VMHostName = "esx"+$x + ".domain.local"

                $esxImpl = Get-VMHost -Name $VMHostName

                $esx = $esxImpl | Get-View

                $ns = Get-View -Id $esx.ConfigManager.NetworkSystem

                foreach($sw in $esx.Config.Network.Vswitch){

                $vsSpec = $sw.Spec

                $vsSpec.Policy.Security.AllowPromiscuous = $false

                $vsSpec.Policy.Security.ForgedTransmits = $false

                $vsSpec.Policy.Security.MacChanges = $false

                $ns.UpdateVirtualSwitch($sw.Name,$vsSpec)

                }

                $progressBar1.increment(1)

                $x ++ } until ($x -eq 4)

                 

                ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>> to :

                 

                $$x = 1

                do {$x;

                $VMHostName = "esx"+$x + ".domain.local"

                $esxImpl = Get-VMHost -Name $VMHostName

                $esx = $esxImpl | Get-View

                $ns = Get-View -Id $esx.ConfigManager.NetworkSystem

                foreach($sw in $esx.Config.Network.Vswitch){

                $vsSpec = $sw.Spec

                $vsSpec.Policy.Security.AllowPromiscuous = $false

                $vsSpec.Policy.Security.ForgedTransmits = $false

                $vsSpec.Policy.Security.MacChanges = $false

                $ns.UpdateVirtualSwitch($sw.Name,$vsSpec)

                $progressBar1.increment(1)

                }

                 

                $x ++ } until ($x -eq 4)

                +++++++++++++++++++++++++++++++++++++++++++++++++++++

                 

                I see the progressbar increasing, and the form looks like it refreshes now..

                Any idea why this behaviour occurs now and not in previous script ?

                • 5. Re: Progressbar problem when running scriptblocks
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  The only difference I see is that the script calls $progressBar1.increment(1) more frequently (once per vswitch).

                  But how this could explain that the progressbar now visibly works is beyond me.

                   

                  Perhaps you try posting the question on the Sapien forum ?

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  1 person found this helpful
                  • 6. Re: Progressbar problem when running scriptblocks
                    dmaster Expert
                    VMware EmployeesvExpert

                    Hi LucD,

                     

                    Thanx for the help..

                     

                     

                    I posted the question on the Sapien forum now.

                     

                     

                    I  quickly received a reply from the Sapien forum.. and there i received the missing line

                     

                     

                     

                     

                     

                    Try using $form1.Refresh() after your increment.

                     

                     

                    Note: These forms are reserved for questions about the Freetools. If you have scripting questions you can post them on ScriptingAnswers.com.