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.
First progress bar for export ad users
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.
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.
First progress bar for export ad users
- Attachments
-
- FirstProgressBarADusersExport.txt
- (1.18 KiB) Downloaded 46 times
Re: First progress bar for export ad users
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.
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.
- $buttonSearch_Click = {
- $progressbar1.Maximum = $AllUsers.Count;
- $progressbar1.Step = 1;
- $progressbar1.Value = 0;
- If ($checkbox1.Checked) {
- #I want to export all users from AD with some values to file and showing progress on progress bar.
- [array]$AllUsers += Get-Aduser -Filter * -Properties samaccountname |
- ForEach-Object{
- $progressbar1.PerformStep();
- [System.Windows.Forms.Application]::DoEvents()
- }
- }else{
- #$textbox1.text is a place where will be write samaccountname user.
- Get-ADUser -Identity $textbox1.Text -Properties * |
- select GivenName, Surname, Name, DisplayName, mailNickname, mail, EmailAddress, Enabled, memberOf |
- Out-GridView
- }
- }