First progress bar for export ad users

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
raf65tuir
Posts: 4
Last visit: Thu Aug 10, 2023 5:11 am

First progress bar for export ad users

Post by raf65tuir »

Hello,
Please indulgence for me, I want to create a first progress bar in the Get-ADUser selection. I have read most of the help on the sapiens pages, but my script doesn't show the progress correctly or doesn't create a file.
Thank you.
Attachments
FirstProgressBarADusersExport.txt
(1.18 KiB) Downloaded 46 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: First progress bar for export ad users

Post by jvierra »

What you are trying to do cannot be done as Get-AdUser is a blocking call. Once event code is blocked then you cannot execute any other code until the bocking ends. Enumerating the result will happen so fast you will not see the pbar increment.

It is also better to increment the value as the method you are using is delayed by messaging and doesn't work well in an event. You can try adding "DoEvents" in the loop which can help.

The following will get you closer. This is also one case where you should void negative logic as it creates confusion for you and others.
  1. $buttonSearch_Click = {
  2.    
  3.     $progressbar1.Maximum = $AllUsers.Count;
  4.     $progressbar1.Step = 1;
  5.     $progressbar1.Value = 0;
  6.    
  7.    
  8.     If ($checkbox1.Checked) {
  9.         #I want to export all users from AD with some values to file and showing progress on progress bar.
  10.         [array]$AllUsers += Get-Aduser -Filter * -Properties samaccountname |
  11.             ForEach-Object{
  12.                 $progressbar1.PerformStep();
  13.                 [System.Windows.Forms.Application]::DoEvents()
  14.             }
  15.     }else{
  16.         #$textbox1.text is a place where will be write samaccountname user.
  17.         Get-ADUser -Identity $textbox1.Text -Properties * |
  18.             select GivenName, Surname, Name, DisplayName, mailNickname, mail, EmailAddress, Enabled, memberOf |
  19.             Out-GridView
  20.     }
  21. }
  22.  
This topic is 1 year and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked